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.
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 <= 10 18).
Each test case comes with a single line with two numbers A and B (0 <= A <= B <= 10 18).
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
jiuwang.jpg;
#include<iostream> using namespace std; int pd(long long n) { int sum=0; while(n){ int z=n%10; sum+=z; n/=10; } return (sum%10==0)?1:0; } int main() { int n; cin>>n; for(int i=1;i<=n;i++){ long long a,b; cin>>a>>b; a--;//if(a==b)的话就无法判断,所以a要-- long long sum1=a/10;//因为每十个有一个,所以可以直接除以10算出整的 for(long long j=a/10*10;j<=a;j++){//遍历找出有没有符合的 if(pd(j)) sum1++; } long long sum2=b/10; for(long long j=b/10*10;j<=b;j++){ if(pd(j)) sum2++; } printf("Case #%d: %lld\n",i,sum2-sum1); } return 0; }