HDU 4722-Good Numbers

来源:互联网 发布:韦德总决赛数据 编辑:程序博客网 时间:2024/05/21 09:09

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

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. 

打表找规律~

发现每100位便可以找到10各个位置加起来是10的倍数的数字...只要判断a 和b 是100的几倍即可~~

CODE:

#include<iostream>#include<stdio.h>#include<string.h>#include<string>using namespace std;int main(){    int T;    scanf("%d",&T);    for(int tt=1;tt<=T;tt++)    {        long long a,b;        scanf("%I64d%I64d",&a,&b);        long long ans=(b/100-a/100)*10;        long long aa=a/100*100;        while(aa<a)        {//printf("1\n");            long long ta=aa;            long long t=0;            while(ta!=0)            {                t+=ta%10;                ta=ta/10;            }            if(t%10==0)            {                ans--;            }            aa++;        }        long long bb=b/100*100;        while(bb<=b)        {//printf("1\n");            long long tb=bb;            long long t=0;            while(tb!=0)            {                t+=tb%10;                tb=tb/10;            }            if(t%10==0)            {                ans++;            }            bb++;        }        printf("Case #%d: %I64d\n",tt,ans);    }    return 0;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 手机酷狗下载要钱怎么办 酷我音乐没有声音怎么办 手机酷我音乐没有声音怎么办 酷我音乐歌曲下载收费怎么办 网易云下载超过每日上限怎么办 全民k歌领不了花怎么办 安卓全民k歌延迟怎么办 全民k歌唱歌延迟怎么办 全民k歌耳机延迟怎么办 word文档打开是乱码怎么办 全民k歌不能录音怎么办 全民k歌登录不上怎么办 平果手机迅雷闪退怎么办 电脑打开央视影音死机怎么办 先锋影音二级网页打不开怎么办 手机qq音乐登录失效怎么办 酷狗账号忘记了怎么办 手机qq音乐听不了歌怎么办 第一试用网密码忘了怎么办 玩h1z1画面卡顿怎么办 uu跑腿抢不到单怎么办 比特币加密忘了怎么办 路虎发现cd卡死怎么办 苹果手机帐号被锁定怎么办 苹果手机帐号锁定了怎么办 微博帐号被锁定怎么办 微博显示帐号被锁定怎么办 uc屏蔽了一个网站怎么办 uu跑腿送货遇到不方便收货怎么办 雷神加速器忘记暂停怎么办 obs直播开摄像头吃鸡掉帧怎么办 陌陌收到的礼物怎么办 吃了油腻的东西恶心怎么办 主播工资不发怎么办 主播工资被欠怎么办 直播平台不发工资坑主播怎么办 主播公司不发工资怎么办 梦幻月卡用完了怎么办 网易星球实名认证通过不了怎么办 认证过荔枝主播怎么办 苹果手机相机不对焦怎么办