import java.io.*; import java.util.*;
public class asceticism{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
}
public static class Pair implements Comparable<Pair>{
int vtx; int val;
public Pair(int a, int b){
this.vtx=a; this.val=b;
}
public int compareTo(Pair other){
if(this.val<other.val)return -1;
if(this.val>other.val)return 1;
if(this.vtx<other.vtx)return -1;
return 1;
}
}
static int MOD=1000000007;
static int[] rk, p,siz;
//Consider putting stuff in K groups of increasing stuff
//Nothing good gets counted twice
//Consider groups that can't be merged
//USE PIE!
public static void main(String[] args){
FastReader br=new FastReader();
int N=br.nextInt(); int K=br.nextInt();
long comb=1;
long ans=0;
for (int i = 0; i < K; i++) {
ans+=(1-2*(i&1))*(pow(K-i,N)*comb)%MOD; ans%=MOD;
comb*=(N+1-i); comb%=MOD;
comb*=pow(i+1, MOD-2); //Inverse of i+1 mod MOD
comb%=MOD;
}
System.out.println((ans+MOD)%MOD);
}
public static long pow(int b, int e){
if(e==0)return 1; if(e==1)return b;
long x=pow(b,e/2); return ((x*x)%MOD)*pow(b,e%2)%MOD;
}
public static int find(int x, int[] p){
if(p[x]==x)return x;
int ans=find(p[x],p); p[x]=ans; return ans;
}
public static void merge(int a, int b) {
if(rk[a]<rk[b]) {
p[a]=b; siz[b]+=siz[a];
}else if(rk[a]==rk[b]) {
p[a]=b; rk[b]++;siz[b]+=siz[a];
}else {
p[b]=a; siz[a]+=siz[b];
}
}
}
//Debugging:
//Are you sure your algorithm is correct?
//Bounds: long
//Special cases: n=0,1?
//Make sure you remove your debugging code before you submit!
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
9064 KB |
Output is correct |
2 |
Correct |
70 ms |
8556 KB |
Output is correct |
3 |
Correct |
69 ms |
8556 KB |
Output is correct |
4 |
Correct |
76 ms |
8448 KB |
Output is correct |
5 |
Correct |
70 ms |
8556 KB |
Output is correct |
6 |
Correct |
72 ms |
8556 KB |
Output is correct |
7 |
Correct |
71 ms |
8556 KB |
Output is correct |
8 |
Correct |
69 ms |
8556 KB |
Output is correct |
9 |
Correct |
70 ms |
8556 KB |
Output is correct |
10 |
Correct |
70 ms |
8556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
9064 KB |
Output is correct |
2 |
Correct |
70 ms |
8556 KB |
Output is correct |
3 |
Correct |
69 ms |
8556 KB |
Output is correct |
4 |
Correct |
76 ms |
8448 KB |
Output is correct |
5 |
Correct |
70 ms |
8556 KB |
Output is correct |
6 |
Correct |
72 ms |
8556 KB |
Output is correct |
7 |
Correct |
71 ms |
8556 KB |
Output is correct |
8 |
Correct |
69 ms |
8556 KB |
Output is correct |
9 |
Correct |
70 ms |
8556 KB |
Output is correct |
10 |
Correct |
70 ms |
8556 KB |
Output is correct |
11 |
Correct |
72 ms |
8684 KB |
Output is correct |
12 |
Correct |
69 ms |
8556 KB |
Output is correct |
13 |
Correct |
70 ms |
8428 KB |
Output is correct |
14 |
Correct |
74 ms |
8556 KB |
Output is correct |
15 |
Correct |
75 ms |
8684 KB |
Output is correct |
16 |
Correct |
74 ms |
8812 KB |
Output is correct |
17 |
Correct |
70 ms |
8556 KB |
Output is correct |
18 |
Correct |
75 ms |
8684 KB |
Output is correct |
19 |
Correct |
71 ms |
8428 KB |
Output is correct |
20 |
Correct |
70 ms |
8556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
9064 KB |
Output is correct |
2 |
Correct |
70 ms |
8556 KB |
Output is correct |
3 |
Correct |
69 ms |
8556 KB |
Output is correct |
4 |
Correct |
76 ms |
8448 KB |
Output is correct |
5 |
Correct |
70 ms |
8556 KB |
Output is correct |
6 |
Correct |
72 ms |
8556 KB |
Output is correct |
7 |
Correct |
71 ms |
8556 KB |
Output is correct |
8 |
Correct |
69 ms |
8556 KB |
Output is correct |
9 |
Correct |
70 ms |
8556 KB |
Output is correct |
10 |
Correct |
70 ms |
8556 KB |
Output is correct |
11 |
Correct |
72 ms |
8684 KB |
Output is correct |
12 |
Correct |
69 ms |
8556 KB |
Output is correct |
13 |
Correct |
70 ms |
8428 KB |
Output is correct |
14 |
Correct |
74 ms |
8556 KB |
Output is correct |
15 |
Correct |
75 ms |
8684 KB |
Output is correct |
16 |
Correct |
74 ms |
8812 KB |
Output is correct |
17 |
Correct |
70 ms |
8556 KB |
Output is correct |
18 |
Correct |
75 ms |
8684 KB |
Output is correct |
19 |
Correct |
71 ms |
8428 KB |
Output is correct |
20 |
Correct |
70 ms |
8556 KB |
Output is correct |
21 |
Correct |
72 ms |
8556 KB |
Output is correct |
22 |
Correct |
72 ms |
8556 KB |
Output is correct |
23 |
Correct |
76 ms |
8800 KB |
Output is correct |
24 |
Correct |
79 ms |
8924 KB |
Output is correct |
25 |
Correct |
76 ms |
8796 KB |
Output is correct |
26 |
Correct |
78 ms |
8812 KB |
Output is correct |
27 |
Correct |
78 ms |
8812 KB |
Output is correct |
28 |
Correct |
75 ms |
8812 KB |
Output is correct |
29 |
Correct |
71 ms |
8556 KB |
Output is correct |
30 |
Correct |
75 ms |
8684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
9064 KB |
Output is correct |
2 |
Correct |
70 ms |
8556 KB |
Output is correct |
3 |
Correct |
69 ms |
8556 KB |
Output is correct |
4 |
Correct |
76 ms |
8448 KB |
Output is correct |
5 |
Correct |
70 ms |
8556 KB |
Output is correct |
6 |
Correct |
72 ms |
8556 KB |
Output is correct |
7 |
Correct |
71 ms |
8556 KB |
Output is correct |
8 |
Correct |
69 ms |
8556 KB |
Output is correct |
9 |
Correct |
70 ms |
8556 KB |
Output is correct |
10 |
Correct |
70 ms |
8556 KB |
Output is correct |
11 |
Correct |
72 ms |
8684 KB |
Output is correct |
12 |
Correct |
69 ms |
8556 KB |
Output is correct |
13 |
Correct |
70 ms |
8428 KB |
Output is correct |
14 |
Correct |
74 ms |
8556 KB |
Output is correct |
15 |
Correct |
75 ms |
8684 KB |
Output is correct |
16 |
Correct |
74 ms |
8812 KB |
Output is correct |
17 |
Correct |
70 ms |
8556 KB |
Output is correct |
18 |
Correct |
75 ms |
8684 KB |
Output is correct |
19 |
Correct |
71 ms |
8428 KB |
Output is correct |
20 |
Correct |
70 ms |
8556 KB |
Output is correct |
21 |
Correct |
72 ms |
8556 KB |
Output is correct |
22 |
Correct |
72 ms |
8556 KB |
Output is correct |
23 |
Correct |
76 ms |
8800 KB |
Output is correct |
24 |
Correct |
79 ms |
8924 KB |
Output is correct |
25 |
Correct |
76 ms |
8796 KB |
Output is correct |
26 |
Correct |
78 ms |
8812 KB |
Output is correct |
27 |
Correct |
78 ms |
8812 KB |
Output is correct |
28 |
Correct |
75 ms |
8812 KB |
Output is correct |
29 |
Correct |
71 ms |
8556 KB |
Output is correct |
30 |
Correct |
75 ms |
8684 KB |
Output is correct |
31 |
Correct |
70 ms |
8644 KB |
Output is correct |
32 |
Correct |
72 ms |
8656 KB |
Output is correct |
33 |
Correct |
81 ms |
8812 KB |
Output is correct |
34 |
Correct |
119 ms |
11160 KB |
Output is correct |
35 |
Correct |
187 ms |
11028 KB |
Output is correct |
36 |
Correct |
196 ms |
11044 KB |
Output is correct |
37 |
Correct |
202 ms |
10792 KB |
Output is correct |
38 |
Correct |
90 ms |
8796 KB |
Output is correct |
39 |
Correct |
135 ms |
11044 KB |
Output is correct |
40 |
Correct |
144 ms |
11044 KB |
Output is correct |