-
Notifications
You must be signed in to change notification settings - Fork 0
/
R-B-A.cpp
70 lines (69 loc) · 1.26 KB
/
R-B-A.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cassert>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <map>
#define PB push_back
#define MP make_pair
#define ms(x, y) memset(x, y, sizeof(x))
using namespace std;
typedef pair<int,int> PII;
typedef long long LL;
const int MOD=1e9+7;
const int maxn=1e5+7;
const double PI=acos(-1.0);
LL dp[10][2][22];
int num[22];
LL dfs(int pos,int sum,int has,int flag){
if(pos==-1){
return (sum%9!=0 && has!=0)? 1:0;
}
if(flag==0 && dp[sum][has][pos]!=-1){
return dp[sum][has][pos];
}
LL ans=0;
int nsum,nhas,nflag;
int end = flag? num[pos]:9;
for(int i=0;i<=end;i++){
nsum = (sum+i) % 9;
nhas = has || (i==9);
nflag = flag && (i==end);
ans += dfs(pos-1, nsum, nhas, nflag);
}
if(!flag){
dp[sum][has][pos]=ans;
}
}
LL solve(LL n){
memset(num, 0, sizeof(num));
memset(dp, -1, sizeof(dp));
int pos=0;
while(n){
num[pos]=n%10;
n/=10;
pos++;
}
return dfs(pos-1,0,0,true);
}
int main() {
int t=1,T;
foreopen("","r",stdin);
foreopen("Alarge.out","w",stdout);
cin>>T;
LL ans=0;
LL m,n;
while(T--){
cin>>m>>n;
LL res1 = solve(m-1);
LL res2 = solve(n);
printf("Case #%d: %lld",t++,res2-res1);
}
return 0;
}