include iostream include string include queue include cmath include se

 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;
inline long long gCount(long long curr, long long maxim)
{
long long answer = 0;
if(curr < 10)
{
answer = (min(maxim, 10ll) - curr);
return answer;
}
if(curr < 100)
{
answer = 2 * (min(maxim, 100ll) - curr);
return answer;
}
if(curr < 1000)
{
answer = 3 * (min(maxim, 1000ll) - curr);
return answer;
}
if(curr < 10000)
{
answer = 4 * (min(maxim, 10000ll) - curr);
return answer;
}
if(curr < 100000)
{
answer = 5 * (min(maxim, 100000ll) - curr);
return answer;
}
if(curr < 1000000)
{
answer = 6 * (min(maxim, 1000000ll) - curr);
return answer;
}
if(curr < 10000000)
{
answer = 7 * (min(maxim, 10000000ll) - curr);
return answer;
}
if(curr < 100000000)
{
answer = 8 * (min(maxim, 100000000ll) - curr);
return answer;
}
if(curr < 1000000000ll)
{
answer = 8 * (min(maxim, 1000000ll) - curr);
return answer;
}
return answer;
}
int main()
{
int n = 0;
int a = 0;
cin >> n >> a;
long long answer = 0;
int maxim = 1;
int ta = a;
while(ta > 0)
{
maxim *= 10;
ta /= 10;
}
int i = 0;
maxim = min(maxim, a + n);
for(i = a; i <= n + a; )
{
answer += gCount(i, maxim);
i = maxim;
if(maxim == min(maxim * 10, n + a))
break;
maxim = min(maxim * 10, n + a);
}
cout << answer;
return 0;
}