Problem 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) , indicating the number of test cases.
Each test case comes with a single line with two numbers A and B (0 <= A <= B <= 1018).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
Hint
The answer maybe very large, we recommend you to use long long instead of int.
思路:通过打表输出发现每十个数之间必有一个符合要求的数字,于是只要从a开始玩后并且从b开始往前找到各自遇到的第一个符合要求的数字,然后除以10再相减即可得到答案,注意无解的情况
AC代码
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define ll long long
int check(ll a)
{
ll sum=0;
while(a)
{
sum+=a%10;
a/=10;
}
return sum%10;
}
int main()
{
ll a,b;
int t;
cin>>t;
for(int k=1;k<=t;k++)
{
cin>>a>>b;
while(check(a))a++;
while(check(b))b--;
ll res;
if(a>b)res=0;
else res=b/10-a/10+1;
printf("Case #%d: %lld\n",k,res);
}
}