Good Numbers

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
题意:给定一个区间,求区间中有多少个满足每位上的数的和是10的倍数。
题解:将一个数分成两部分,前面部分+个位数。因为平均10个数里面必然有1个这样的数。比方说1234,1+2+3+4=10,此时刚好对于取余等于零,为123+1.如果个位数小于10-前面位数的和,则为122+1.大于也是123+1.加1是因为要加上0的情况。wrong到海枯石烂因为没考虑这个
#include<stdio.h>
#include<iostream>
#define ll __int64
using namespace std;
ll lmx(ll m)
{
 m/=10;
   ll temp=m,sum=0;
   while(temp)
   {
    sum+=temp%10;
    temp/=10;
   }
   return sum%10;
}
int main()
{
  freopen("in.txt","r",stdin);
  freopen("sadf.txt","w",stdout);
 ll test,ca=0,l,r;
 ll a,b;
 scanf("%I64d",&test);
    while(test--)
 {
       ca++;
    scanf("%I64d %I64d",&a,&b);
    printf("Case #%I64d: ",ca);
    if(a<=10) l=0;
    else
    {
    a-=1;
    if(a%10>=10-lmx(a)||lmx(a)==0) l=a/10;
    else l=a/10-1;
    }
    if(b<=10) r=0;
    else
    {
    if(b%10>=10-lmx(b)||lmx(b)==0) r=b/10;
    else r=b/10-1;
    }
    if(a==0) printf("%I64d\n",r-l+1);
    else printf("%I64d\n",r-l);
 }
}
posted @ 2013-09-12 20:35  forevermemory  阅读(442)  评论(0编辑  收藏  举报