View Code of Problem 3920

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main(void)
{

    int arr[][11] = {
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 45},
        {2, 4, 6, 8, 0, 2, 4, 6, 8, 0, 40},
        {3, 6, 9, 2, 5, 8, 1, 4, 7, 0, 45},
        {4, 8, 2, 6, 0, 4, 8, 2, 6, 0, 40},
        {5, 0, 5, 0, 5, 0, 5, 0, 5, 0, 25},
        {6, 2, 8, 4, 0, 6, 2, 8, 4, 0, 40},
        {7, 4, 1, 8, 5, 2, 9, 6, 3, 0, 45},
        {8, 6, 4, 2, 0, 8, 6, 4, 2, 0, 40},
        {9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 45}};

    int t;
    cin >> t;
    long long n, m;
    for (int i = 0; i < t; i++)
    {
        cin >> n >> m;
        int tmp = m % 10;
        long long num = n / m;
        long long tmp1 = num / 10;
        long long tmp2 = num % 10;
        long long sum = tmp1 * arr[tmp][10];
        for (int j = 0;j  < tmp2;j++)
            sum += arr[tmp][j];
        cout << sum << endl;
    }
}

Double click to view unformatted code.


Back to problem 3920