QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#627918 | #8339. Rooted Tree | xmseer# | TL | 273ms | 58796kb | Java11 | 1.0kb | 2024-10-10 17:38:10 | 2024-10-10 17:38:12 |
Judging History
answer
import java.util.Scanner;
public class Main {
private static long modInverse(long a, int mod) {
return power(a, mod - 2, mod);
}
private static long power(long base, int exp, int mod) {
if(base==0){
return 0;
}
if(exp==1){
return base;
}
if((exp&1)==1){
return (power((base*base)%mod,(exp>>1),mod)*base)%mod;
}else{
return power((base*base)%mod,(exp>>1),mod);
}
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int k=sc.nextInt();
int mod=(int)1e9+9;
long ans=0;
long v=0;
long sum=1;
for (int i = 1; i <=k ; i++) {
ans+=(v+1)*n;
ans%=mod;
v=((v+1)*n+(sum-1)*v)%mod*modInverse((sum+n-1)%mod,mod);
v%=mod;
sum=sum-1+n;
sum%=mod;
// System.out.println(ans);
}
System.out.println(ans);
}
}
详细
Test #1:
score: 100
Accepted
time: 85ms
memory: 58796kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 89ms
memory: 53708kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 273ms
memory: 54220kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: -100
Time Limit Exceeded
input:
48 6713156