View Code of Problem 3920

#include<iostream>
#include<string>
#include<algorithm>
#include<stack>

using namespace std;

//0:0000000000
//1:0123456789
//2:0246802468
//3:0369258147
//4:0482604826
//5:0505050505
//6:0628406284
//7:0741852963
//8:0864208642
//9:0987654321


int main() {
	int t;
	long long m, n;
	cin >> t;
	int arr[10][10] = { 
	{0,0,0,0,0,0,0,0,0,0},
	{0,1,2,3,4,5,6,7,8,9},
	{0,2,4,6,8,0,2,4,6,8},
	{0,3,6,9,2,5,8,1,4,7},
	{0,4,8,2,6,0,4,8,2,6},
	{0,5,0,5,0,5,0,5,0,5},
	{0,6,2,8,4,0,6,2,8,4},
	{0,7,4,1,8,5,2,9,6,3},
	{0,8,6,4,2,0,8,6,4,2},
	{0,9,8,7,6,5,4,3,2,1} };
	int a[10] = { 0,45,40,45,40,25,40,45,40,45 };
	while (t--)
	{
		cin >> n >> m;
		if (m > n)
			cout << 0 << endl;
		else if (m % 10 == 0)
			cout << 0 << endl;
		else
		{
			int temp = m % 10;  //取得末尾数字
			long long num = n / m; //n中有几个m
			long long temp1 = num / 10;  //10个/轮 总共temp1轮
			long long temp2 = num % 10;  //剩下不到10个,逐个相加
			long long sum = temp1 * a[temp]; //总轮数*对应m每轮的值
			for (int i = 0; i <= temp2; i++)  //剩下不到1轮的末尾值逐个相加
				sum += arr[temp][i];
			cout << sum << endl;
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3920