/
main.cpp
67 lines (51 loc) · 1.18 KB
/
main.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
// [uVa] 10994 - Simple Addition
// https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1935
//
// code by Jason Huang aka Einz
// github: https://github.com/PM25
// website: https://pm25.github.io
// discord: https://discord.gg/G4jEeDC
// email: jason199786109@gmail.com
#include <iostream>
using namespace std;
int f(int n);
long long int sum(int from, int to);
long long int f_sum(int from, int to);
int main(){
int s, q;
while(cin>>s>>q){
if(s<0 && q<0) break;
cout<<f_sum(s, q)<<endl;
}
}
int f(int n)
{
if(n%10) return n%10;
else if(!n) return 0;
else return n/10;
}
long long int sum(int from, int to)
{
int count = to - from + 1;
return (from+to) * count / 2;
}
long long int f_sum(int from, int to)
{
long long ans(0);
if((from/10) == (to/10)){
ans += sum(f(from), f(to));
}
else{
if(from%10){
ans += sum(f(from), 9);
from += (10-from%10);
}
if(to%10){
ans += sum(1, f(to));
to -= to%10;
}
ans += (sum(1, 9) * (to/10 - from/10));
ans += f_sum(from/10, to/10);
}
return ans;
}