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.
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
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
- HDU 4722 Good Numbers
- HDU 4722 Good Numbers
- Hdu 4722 Good Numbers
- hdu 4722 Good Numbers
- HDU 4722 Good Numbers
- HDU 4722 Good Numbers
- hdu 4722 Good Numbers
- HDU 4722 Good Numbers
- HDU 4722 Good Numbers
- HDU 4722-Good Numbers
- HDU 4722 Good Numbers
- hdu 4722 Good Numbers
- HDU 4722 Good Numbers
- hdu 4722 good numbers
- 【HDU】 4722 Good Numbers
- HDU 4722 Good Numbers
- hdu 4722 Good Numbers
- hdu 4722 Good Numbers(dp)
- Redis 订阅与发布
- 李红霞作业第二章18题
- qtableview划过变色
- java基础2:抽象类、接口与多态
- 学习学习再学习
- hdu 4722 Good Numbers
- LinkedList源码分析
- Ubuntu下搭建LNMP(apt-get方式安装)
- Android加载图片导致内存溢出(Out of Memory异常
- Effective C++读后感:析构函数注意事项
- 内部排序:希尔、快速、堆、归并等排序算法Java实现
- p51页 第二章 第17题 潘璠
- MAC安装PIL
- java基础3:多线程