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
HintThe answer maybe very large, we recommend you to use long long instead of int.
如果我们把一个数字的每一个数字加起来,结果正好可以被10除,我们就说这个数字是个好数字。
你需要计算从A到B(含)范围内的好数字。
输入
第一行有一个数字T(T<=10000),表示测试用例的数量。
每个测试用例都有一行带有两个数字a和B(0<=a<=B<=1018)。
输出
对于测试用例X,首先输出“case#X:”,然后在一行中输出正确的数字。
样本输入
2
1 10
1 20
样本输出
Case #1: 0
Case #2: 1
提示
答案可能很大,我们建议您使用long long而不是int。
解题思路
#include <stdio.h>
int pd(long long a) //判断是否是好数
{
long long k=0;
while(a!=0){
k=k+a%10;
a=a/10;
}
if(k%10==0){
return 1;
}
else{
return 0;
}
}
int main()
{
int T,i;
long long res,a,b,sum,t;
scanf("%d",&T);
for(i=1;i<=T;i++)
{
scanf("%lld %lld",&a,&b);
while(pd(a)==0){ //从a到b找出第一个好数
a++;
}
while(pd(b)==0){ //从a到b找出最后一个好数
b--;
}
if(a>b){ //如果a大于b,则没有好数
res=0;
}
else{ //如果a<=b则有好数
res=b/10-a/10+1; //res为好数个数
}
printf("Case #%d: %lld\n",i,res);
}
return 0;
}