QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#627918#8339. Rooted Treexmseer#TL 273ms58796kbJava111.0kb2024-10-10 17:38:102024-10-10 17:38:12

Judging History

你现在查看的是最新测评结果

  • [2024-10-10 17:38:12]
  • 评测
  • 测评结果:TL
  • 用时:273ms
  • 内存:58796kb
  • [2024-10-10 17:38:10]
  • 提交

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

output:


result: