QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#710493#8339. Rooted TreeNew_Folder#WA 165ms214824kbC++20886b2024-11-04 20:05:232024-11-04 20:05:23

Judging History

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

  • [2024-11-04 20:05:23]
  • 评测
  • 测评结果:WA
  • 用时:165ms
  • 内存:214824kb
  • [2024-11-04 20:05:23]
  • 提交

answer

#pragma GCC optimize(2)
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod=1e9+9;
ll a[10000001];
ll pre[10000001];
ll sv[10000001];
ll inv[10000001];
ll fastpow(ll base,ll po){
	ll ans=1;
	while(po){
		if(po&1){
			ans=ans*base%mod;
		}
		base=base*base%mod;
		po>>=1;
	}
	return ans;
}
void solve(){
	ll m,k;
	cin>>m>>k;
	pre[0]=1;
	for(int i=1;i<=k;i++){
		a[i]=i*(m-1)+1;
		pre[i]=pre[i-1]*a[i]%mod;
	}
	sv[k]=fastpow(pre[k],mod-2);
	for(int i=k-1;i>=0;i--){
		sv[i]=sv[i+1]*a[i+1]%mod;
	}
	for(int i=1;i<=k;i++){
		inv[i]=sv[i]*pre[i-1]%mod;
	}
	ll ans=m*k;
	ll temp=0;
	for(int i=1;i<=k-1;i++){
		temp+=inv[i]*(k-i)%mod;
		temp%=mod;
	}
	temp=temp*m%mod*m%mod;
	ans=ans+temp%mod;
	cout<<ans;
}
int main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 2

output:

18

result:

ok 1 number(s): "18"

Test #2:

score: 0
Accepted
time: 0ms
memory: 9780kb

input:

2 6

output:

600000038

result:

ok 1 number(s): "600000038"

Test #3:

score: 0
Accepted
time: 18ms
memory: 31428kb

input:

83 613210

output:

424200026

result:

ok 1 number(s): "424200026"

Test #4:

score: -100
Wrong Answer
time: 165ms
memory: 214824kb

input:

48 6713156

output:

1198541590

result:

wrong answer 1st numbers differ - expected: '198541581', found: '1198541590'