hdu 4722 Good Numbers

来源:互联网 发布:数据库创建主键约束 编辑:程序博客网 时间:2024/05/11 01:29
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 <= 10 18).
 

Output

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

Sample Input

21 101 20
 

Sample Output

Case #1: 0Case #2: 1

Hint

The answer maybe very large, we recommend you to use long long instead of int.


该题的意思是 a到b 区间,求能整除10的 和后位相加能整除10的 1-10是1,。。。主要是long long 难搞~~

#include <iostream>#include <stdio.h>#include <string.h>int zi(long long int n) {    int sum=0;    long long int p=n/10*10;    long long int m = n;    for(;p<=m;p++)    {        n=p;        sum=0;        while(n)        {            sum+=n%10;            n/=10;        }        if(sum%10==0) return 1;    }    return 0;}long long int shu(long long int n){    if(n<0) return 0;    if(n<=10)   return 1;    long long int q=n/10;    return q+zi(n);}int main(){    int bbs,k=1;    scanf("%d",&bbs);    while(bbs--)    {        long long int a,b;        scanf("%lld%lld",&a,&b);        printf("Case #%d: %lld\n",k,shu(b)-shu(a-1));        k++;    }    return 0;}


0 0