-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP7.java
45 lines (37 loc) · 978 Bytes
/
P7.java
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
import java.util.Arrays;
import java.util.Scanner;
class P7 {
public static int dist(int x, int y){
int a[]=new int[4];
int b[]=new int[4];
for(int i=0; i<4; i++){
a[i]=x%10;
x/=10;
}
for(int i=0; i<4; i++){
b[i]=y%10;
y/=10;
}
Arrays.sort(a);
Arrays.sort(b);
int ans=Math.abs(a[0]-b[0])+Math.abs(a[1]-b[1])+Math.abs(a[2]-b[2])+Math.abs(a[3]-b[3]);
return ans;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int i=0; i<t; i++) {
int l=in.nextInt();
int r=in.nextInt();
int ans=0;
int mod=1000000007;
for(int k=l; k<=r; k++){
for(int j=l; j<=r; j++){
ans+=dist(k,j);
}
ans%=mod;
}
System.out.println(ans);
}
}
}