Good Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 428    Accepted Submission(s): 149

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

Hint

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

 
Source

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<iomanip>
#define INF 99999999
using namespace std; const int MAX=22;
__int64 dp[MAX][10];//分别代表长度为i位数和mod 10为j的个数
int digit[MAX]; void digit_dp(){//计算每长度为i为的数mod 10 == 0的个数
dp[0][0]=1;
for(int i=1;i<MAX;++i){
for(int j=0;j<10;++j){
for(int k=0;k<10;++k){
dp[i][j]+=dp[i-1][(j-k+10)%10];
}
}
}
} __int64 calculate(__int64 n){
int size=0,last=0;
__int64 sum=0;
while(n)digit[++size]=n%10,n/=10;
for(int i=size;i>=1;--i){
for(int j=0;j<digit[i];++j){
sum+=dp[i-1][((0-j-last)%10+10)%10];
}
last=(last+digit[i])%10;
}
return sum;
} int main(){
digit_dp();
int t,num=0;
__int64 a,b;
scanf("%d",&t);
while(t--){
scanf("%I64d%I64d",&a,&b);
printf("Case #%d: %I64d\n",++num,calculate(b+1)-calculate(a));
}
return 0;
}

最新文章

  1. 7 款免费的 Metro UI 模板
  2. 图解HTTPS协议加密解密全过程
  3. 20145213祁玮のJava课程总结
  4. Delphi 实现16进制转字符串及字符串(中文)转16进制
  5. SQL Server 批量插入数据的两种方法(转)
  6. 单步运行linux kernel ?
  7. 保持iOS上键盘出现时输入框不被覆盖
  8. DQL_数据查询语言
  9. 红豆带你从零学C#系列之:初识继承与多态
  10. windows下使用openssl的一种方法
  11. MySql中利用insert into select 准备数据uuid主键冲突
  12. 手写JAVA虚拟机(三)——搜索class文件并读出内容
  13. 415 DOM 查找列表框、下拉菜单控件、对表格元素/表单控件进行增删改操作、创建元素并且复制节点与删除、 对表格操作、通用性和标准的事件监听方法(点击后弹窗效果以及去掉效果)
  14. 机器学习之正则化(Regularization)
  15. [UGUI]游戏中的Tips贴图标边缘显示(贴边)
  16. mysql字符串处理
  17. LOJ1070(SummerTrainingDay05-B 矩阵快速幂)
  18. 多种数据库之间的同步工具SymmetricDS
  19. 可以ping通ip地址,但是访问80,或者8080报错
  20. java Exception 出错的栈信息打印到日志中 打印堆栈信息

热门文章

  1. BZOJ 1620: [Usaco2008 Nov]Time Management 时间管理( 二分答案 )
  2. django1.6.x(python3.3)使用pymysql连接mysql
  3. wget 无法下载jdk的处理办法
  4. Properties的使用
  5. C# 常用参数
  6. QT 程序自定义插件
  7. python的二维数组操作
  8. 剖析MFC六大关键技术(五六)--消息映射与命令传递
  9. 九、cocos2dx之Actions
  10. HH的军训(容斥)