/
SWAcademy 5604
43 lines (40 loc) · 946 Bytes
/
SWAcademy 5604
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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Solution {
static long ans;
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
for (int t = 1; t <= T; t++) {
StringTokenizer st = new StringTokenizer(br.readLine());
long A = Long.parseLong(st.nextToken());
long B = Long.parseLong(st.nextToken());
ans = 0;
long pos = 1;
while(A<=B) {
while(A%10 != 0 && A<=B) {
calc(A,pos);
A++;
}
if(A>B || (A==0 && B== 0)) break;
while(B%10 != 9 && A<=B) {
calc(B,pos);
B--;
}
A/=10;
B/=10;
long m = (B - A + 1) * pos;
ans+= m*45;
pos *= 10;
}
System.out.println("#"+t+" "+ans);
}
}
static void calc(long n, long t) {
while(n>0) {
ans+= (n % 10)*t;
n/= 10;
}
}
}