forked from sdssudhu/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCPCRC1C.cpp
More file actions
78 lines (71 loc) · 1.33 KB
/
Copy pathCPCRC1C.cpp
File metadata and controls
78 lines (71 loc) · 1.33 KB
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
71
72
73
74
75
76
77
78
//CPCRC1C --- SPOJ
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
using namespace std;
int ar[20],ar2[20],len1,len2;
void preprocess(ll a)
{
int i=0;
len1=0;
while(a>0)
{
ar[i]=a%10;
a=a/10;
++len1;
++i;
}
reverse(ar,ar+len1);
}
ll solve(ll i,ll sum)
{
if(i==len1)
return sum;
int j=0;
ll ans=0;
while(j<ar[i])
{
ans=ans+(sum+j)*pow(10,(len1-1-i))+1LL*pow(10,(len1-1-i-1))*45*(len1-1-i);
++j;
}
ans=ans+solve(i+1,sum+ar[i]);
return ans;
}
int main()
{
std::ios::sync_with_stdio(false);
int T;
T=1;
ll a,b;
while(cin>>a>>b)
{
if(a==-1)
break;
preprocess(b);
ll ans=solve(0,0);
preprocess(a-1);
ans=ans-solve(0,0);
cout<<ans<<endl;
}
return 0;
}