-
Notifications
You must be signed in to change notification settings - Fork 1
/
Merge List
141 lines (80 loc) · 2.78 KB
/
Merge List
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
public class Merge_List {
static int testCases;
static long n,m;
static BufferedReader in=new BufferedReader( new InputStreamReader( System.in ) );
static PrintWriter out=new PrintWriter( System.out );
static BigInteger mod=BigInteger.valueOf(10).pow(9).add( BigInteger.valueOf(7) );
static long fact[]=new long[201];
static void preCalculate(){
long f=1;
for(int i=1;i<=200;i++){
f=(f*i)%mod.longValue();
fact[i]=f;
}
}
public static void main(String[] args) throws IOException {
testCases=Integer.parseInt( in.readLine() );
preCalculate();
for(int i=0;i<testCases;i++){
String x[]=in.readLine().split("\\s");
n=Long.parseLong( x[0] );
m=Long.parseLong( x[1] );
long up=fact[ (int)(n+m) ]%mod.longValue();
long down=(fact[(int)n]*fact[(int)m])%mod.longValue();
long ans=modInverse(down,mod.longValue());
//BigInteger temp= BigInteger.valueOf(down);
//BigInteger ans=temp.modInverse( (mod) );
System.out.println( (up*ans)%mod.longValue() );
//BigInteger s=new BigInteger( String.valueOf(down) );
//BigInteger temp;
//if( s.gcd( mod ).equals( BigInteger.ONE ) ){
//temp=s.modInverse(mod);
//System.out.println( BigInteger.valueOf(up).multiply(temp).mod(mod) );
//}
}
}
// static long x,y,x1,y1;
static long p[]=new long [2];
static class INTWrapper{
long c;
public INTWrapper() {
}
public INTWrapper(long c) {
this.c = c;
}
}
static long egcd(long a,long b,INTWrapper x,INTWrapper y){
if( a==0 ){
// p[0]=0;
//p[1]=1;
x.c=0;
y.c=1;
return b;
}
INTWrapper x1=new INTWrapper();
INTWrapper y1=new INTWrapper();
long gcd=egcd( b%a,a,x1,y1 );
x.c=y1.c-(b/a)*x1.c;
y.c=x1.c;
return gcd;
}
static long modInverse(long a,long b){
INTWrapper a1=new INTWrapper(0);
INTWrapper b1=new INTWrapper(1);
long g=egcd(a,b,a1,b1);
//System.out.println("x: "+p[0]+" y: "+p[1]+" mod: "+mod.longValue());
long ans=( (a1.c%mod.longValue())+mod.longValue() )%mod.longValue();
return ans;
}
}
/*5
59 67
47 40
40 32
40 70
75 66*/