QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#675608 | #8339. Rooted Tree | keke | AC ✓ | 1484ms | 122584kb | C++20 | 1.6kb | 2024-10-25 18:57:17 | 2024-10-25 18:57:18 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
template <typename T>
inline void read(T &s)
{
s=0;int f=1;char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-f;
for(;ch>='0'&&ch<='9';ch=getchar())s=s*10+ch-'0';
s*=f;
}
template <typename T> inline void CKmax(T &x,const T &y){if(x<y)x=y;}
template <typename T> inline void CKmin(T &x,const T &y){if(x>y)x=y;}
#define ll long long
#define ull unsigned ll
#define Vint std::vector<int>
const int Mod=1e9+9;
void Add(int &x,int y){x+=y;if(x>=Mod)x-=Mod;}
void Dec(int &x,int y){x-=y;if(x<0)x+=Mod;}
void Mul(int &x,int y){x=1ll*x*y%Mod;}
int Pow(int a,int b){int res=1;for(;b;b>>=1,Mul(a,a))if(b&1)Mul(res,a);return res;}
int Inv(int a){return Pow(a,Mod-2);}
const int N=1e7+99;
int inv[N];
int PM[N],P[N],invP[N],tmp[N],tp[N];
signed main()
{
int m,k;read(m);read(k);
if(m==1)return printf("%lld\n",1ll*k*(k+1)/2%Mod),0;
PM[0]=1;for(int i=1;i<=k;i++)PM[i]=1ll*PM[i-1]*m%Mod;
for(int i=1;i<=k;i++)Add(PM[i],PM[i-1]);
for(int i=1;i<=k;i++)P[i]=1ll*(i-1)*(m-1)%Mod,Add(P[i],1),invP[i]=Inv(P[i]);
int ans=0,Fp=0,F=1;
for(int i=0;i<k;i++)
{
int s=1ll*m*Fp%Mod;Add(s,F);
//printf("!%d\n",s);
Mul(s,invP[i+1]);
Add(ans,s);
int valP=1ll*m*invP[i+1]%Mod;Add(valP,1);Dec(valP,invP[i+1]);
Mul(Fp,valP);
Add(Fp,1ll*F*invP[i+1]%Mod);
Mul(F,valP);
//printf("!Fp=%d F=%d valP=%d\n",Fp,F,valP);
}
Mul(ans,m);
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9960kb
input:
6 2
output:
18
result:
ok 1 number(s): "18"
Test #2:
score: 0
Accepted
time: 1ms
memory: 9936kb
input:
2 6
output:
600000038
result:
ok 1 number(s): "600000038"
Test #3:
score: 0
Accepted
time: 93ms
memory: 20192kb
input:
83 613210
output:
424200026
result:
ok 1 number(s): "424200026"
Test #4:
score: 0
Accepted
time: 987ms
memory: 89820kb
input:
48 6713156
output:
198541581
result:
ok 1 number(s): "198541581"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3740kb
input:
1 111
output:
6216
result:
ok 1 number(s): "6216"
Test #6:
score: 0
Accepted
time: 1070ms
memory: 96040kb
input:
28 7304152
output:
457266679
result:
ok 1 number(s): "457266679"
Test #7:
score: 0
Accepted
time: 591ms
memory: 59096kb
input:
38 4101162
output:
232117382
result:
ok 1 number(s): "232117382"
Test #8:
score: 0
Accepted
time: 1450ms
memory: 122512kb
input:
51 9921154
output:
340670552
result:
ok 1 number(s): "340670552"
Test #9:
score: 0
Accepted
time: 270ms
memory: 34508kb
input:
79 1801157
output:
620550406
result:
ok 1 number(s): "620550406"
Test #10:
score: 0
Accepted
time: 794ms
memory: 73448kb
input:
22 5417157
output:
457449071
result:
ok 1 number(s): "457449071"
Test #11:
score: 0
Accepted
time: 478ms
memory: 46796kb
input:
25 3210162
output:
36368303
result:
ok 1 number(s): "36368303"
Test #12:
score: 0
Accepted
time: 418ms
memory: 44844kb
input:
67 2919160
output:
935195555
result:
ok 1 number(s): "935195555"
Test #13:
score: 0
Accepted
time: 1262ms
memory: 108392kb
input:
77 8613163
output:
482832472
result:
ok 1 number(s): "482832472"
Test #14:
score: 0
Accepted
time: 1463ms
memory: 122532kb
input:
90 10000000
output:
275581651
result:
ok 1 number(s): "275581651"
Test #15:
score: 0
Accepted
time: 1473ms
memory: 122500kb
input:
99 9999999
output:
126087169
result:
ok 1 number(s): "126087169"
Test #16:
score: 0
Accepted
time: 1484ms
memory: 122584kb
input:
100 10000000
output:
451590067
result:
ok 1 number(s): "451590067"
Extra Test:
score: 0
Extra Test Passed