QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#641480#8339. Rooted Treezrj66TL 150ms10844kbC++201.4kb2024-10-14 20:42:432024-10-14 20:42:44

Judging History

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

  • [2024-10-14 20:42:44]
  • 评测
  • 测评结果:TL
  • 用时:150ms
  • 内存:10844kb
  • [2024-10-14 20:42:43]
  • 提交

answer

#include <bits/stdc++.h>

#define x first
#define y second
#define min(a, b) ((a) < (b)?(a):(b))
#define max(a, b) ((a) > (b)?(a):(b))

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL, LL> PLL; 
using PIII = pair<int, PII>;
using i128 = __int128;
using ULL = unsigned long long;

const int N = 10000100, M = 60010, MOD = 1e9 + 9, Base = 13331;
const int inf = 2e9, xf3 = 0x3f3f3f3f;
const LL INF = 4e18, XF3 = 0x3f3f3f3f3f3f3f3f;


LL n;
int K;
string s;
LL fact[N], infact[N];

LL qmi(LL a, LL b, LL p){
    i128 res = 1;
    while(b){
        if(b&1)res = res * a % p;
        b >>= 1;
        a = (i128)a * a % p;
    }
    return res;
}

void init(int nn){
    fact[0] = infact[0] = 1;

    for(int i = 1; i <= nn; i ++){
        infact[i] = qmi((((n - 1) * (i)) + 1) % MOD, MOD - 2, MOD);
    }    
}

void solve(){ 
    
    cin >> n >> K;
    init(K);
    LL A = 0; 
    LL ans = 0;
    for(int i = 0; i < K; i ++){
        ans = (ans + (A * infact[i] % MOD + 1) % MOD) % MOD;
        A = A * ((n - 1LL) * (i + 1) % MOD + 1) % MOD * infact[i] % MOD + n;
        A = A % MOD;
    }
    cout << ans * n % MOD << "\n";
    
    return;
}

int main(){
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0); 
	
	//cout<<fixed<<setprecision(0)<<"\n";
    int _ = 1;  
	// cin>>_;
	
	while(_ --){
		solve();
	} 
	
	return 0;
}

/*

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5672kb

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5652kb

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 150ms
memory: 10844kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: -100
Time Limit Exceeded

input:

48 6713156

output:


result: