Description:

If we sum up every digit of a number and the result can be exactly divided by 10, we say this number is a good number.
You are required to count the number of good numbers in the range from A to B, inclusive.

Input:

The first line has a number T ( T 10000 ) T (T \le 10000) T(T10000) , indicating the number of test cases.
Each test ca***es with a single line with two numbers A and B ( 0 A B 1 0 18 0 \le A \le B \le 10^{18} 0AB1018).

Output:

For test case X, output "Case #X: " first, then output the number of good numbers in a single line.

Sample Input:

2
1 10
1 20

Sample Output:

Case #1: 0
Case #2: 1

题目链接

题目要求输出范围之内各位数之和是10的倍数的数字数量,由于最大范围达到 1 0 18 10^{18} 1018所以肯定无法暴力解题,通过不完全归纳法找规律可以发现每10个数中必定有一个数各位数之和是10的倍数,所以可以用n/10求得结果,然后再计算n-n%10~n之内是否存在一个各位数之和是10的倍数的数,如果存在则结果加一。

AC代码:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5+5;
const double eps = 1e-5;
const double e = 2.718281828459;

int Cal_digit_sum(ll x) {
    int digit_sum_ans = 0;
    while (x) {
        digit_sum_ans += x % 10;
        x /= 10;
    }
    return digit_sum_ans;
}

ll Cal_ans(ll x) {
    ll ans = 0;
    ans += x / 10;
    for (ll i = (x - x % 10); i <= x; ++i) {
        if (Cal_digit_sum(i) % 10 == 0) {
            ans++;
            break;
        }
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    for (int Case = 1; Case <= t; ++Case) {
        ll st, en;
        cin >> st >> en;
        cout << "Case #" << Case << ": " << Cal_ans(en) - Cal_ans(st - 1) << endl;
    }
    return 0;
}