HDU-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 <= 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

找规律的题目!

你发现每10个数有一个符合条件的

但是你直接从A,B范围中找是不容易的

因为有个0

零也符合条件,如果直接找思路有点乱的话可能给你弄的内分泌失调!

那么怎么弄?

给出A,B找出0-A有几个符合条件,找出0-B有几个符合条件

两个一减就OK了!

下面上代码

!注意,所有的都要用long long !不用longlong 就是WA!

#include<stdio.h>
int judge(long long a)
{
    int flag=0,l,k=0;
    while(a>0)
    {
        k+=a%10;
        a=a/10;
    }
    if(k%10==0)
    {
        flag=1;
    }
    return flag;
}
int main()
{
    int t,step=0;
    scanf("%d",&t);
    while(t--)
    {
        step++;
        long long a,b,num,sum,m,i,j;
        scanf("%lld%lld",&a,&b);
        num=0,sum=0,m=0,a--;
        num=a/10;
        for(j=a/10*10;j<=a;j++)
        {
            if(judge(j))
            {
                num++;
            }
        }
        sum=b/10;
        for(i=b/10*10;i<=b;i++)
        {
            if(judge(i))
            {
                sum++;
            }
        }
        //printf("%lld %lld\n",num,sum);
        printf("Case #%d: %lld\n",step,sum-num);
    }
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值