QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#276726 | #6360. 求和 | SoyTony | 100 ✓ | 50ms | 13088kb | C++14 | 2.4kb | 2023-12-06 10:06:33 | 2023-12-06 10:06:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=(1<<18)+10;
const int mod=998244353;
inline int read(){
int x=0,w=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
return x*w;
}
inline int q_pow(int A,int B,int P){
int res=1;
while(B){
if(B&1) res=1ll*res*A%P;
A=1ll*A*A%P;
B>>=1;
}
return res;
}
struct Poly{
const int g=3;
const int inv_g=332748118;
int f[maxn],r[maxn];
int base,w[maxn];
int& operator[](const int &i){return f[i];}
int operator[](const int &i)const{return f[i];}
inline void NTT(int L,bool type){
for(int i=1;i<L;++i){
r[i]=(r[i>>1]>>1)+(i&1?L>>1:0);
if(i<r[i]) swap(f[i],f[r[i]]);
}
for(int d=1;d<L;d<<=1){
base=q_pow(type?g:inv_g,(mod-1)/(2*d),mod);
w[0]=1;
for(int i=1;i<d;++i) w[i]=1ll*w[i-1]*base%mod;
for(int i=0;i<L;i+=d<<1){
for(int j=0;j<d;++j){
int x=f[i+j],y=1ll*w[j]*f[i+d+j]%mod;
f[i+j]=(x+y)%mod,f[i+d+j]=(x-y+mod)%mod;
}
}
}
if(!type){
int inv_L=q_pow(L,mod-2,mod);
for(int i=0;i<L;++i) f[i]=1ll*f[i]*inv_L%mod;
}
}
}F,G,H;
int n;
int pw[maxn],fact[maxn],fact_inv[maxn],sumq[maxn];
int ans;
int main(){
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
n=read();
pw[0]=fact[0]=fact_inv[0]=1;
for(int i=1;i<=n;++i){
pw[i]=1ll*pw[i-1]*2%mod;
fact[i]=1ll*fact[i-1]*i%mod;
}
sumq[0]=1,sumq[1]=n+1;
for(int i=2;i<=n;++i) sumq[i]=1ll*(q_pow(i,n+1,mod)-1+mod)%mod*q_pow(i-1,mod-2,mod)%mod;
fact_inv[n]=q_pow(fact[n],mod-2,mod);
for(int i=n-1;i>=1;--i) fact_inv[i]=1ll*fact_inv[i+1]*(i+1)%mod;
for(int i=0;i<=n;++i){
F[i]=1ll*pw[i]*fact[i]%mod;
G[n-i]=(i&1)?(mod-fact_inv[i]):fact_inv[i];
}
int L=1;
while(L<2*n+1) L<<=1;
F.NTT(L,1),G.NTT(L,1);
for(int i=0;i<L;++i) H[i]=1ll*F[i]*G[i]%mod;
H.NTT(L,0);
for(int k=0;k<=n;++k){
int now=H[n+k];
now=1ll*now*sumq[k]%mod*fact_inv[k]%mod%mod;
ans=(ans+now)%mod;
}
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 0ms
memory: 5716kb
input:
7
output:
2442783
result:
ok 1 number(s): "2442783"
Test #2:
score: 10
Accepted
time: 26ms
memory: 9284kb
input:
52011
output:
102651826
result:
ok 1 number(s): "102651826"
Test #3:
score: 10
Accepted
time: 0ms
memory: 5952kb
input:
10
output:
938993060
result:
ok 1 number(s): "938993060"
Test #4:
score: 10
Accepted
time: 1ms
memory: 5716kb
input:
100
output:
228284059
result:
ok 1 number(s): "228284059"
Test #5:
score: 10
Accepted
time: 47ms
memory: 12988kb
input:
100000
output:
996460248
result:
ok 1 number(s): "996460248"
Test #6:
score: 10
Accepted
time: 50ms
memory: 12756kb
input:
87890
output:
886498924
result:
ok 1 number(s): "886498924"
Test #7:
score: 10
Accepted
time: 7ms
memory: 6468kb
input:
12129
output:
308810060
result:
ok 1 number(s): "308810060"
Test #8:
score: 10
Accepted
time: 0ms
memory: 5636kb
input:
609
output:
862812323
result:
ok 1 number(s): "862812323"
Test #9:
score: 10
Accepted
time: 1ms
memory: 5956kb
input:
978
output:
983860140
result:
ok 1 number(s): "983860140"
Test #10:
score: 10
Accepted
time: 43ms
memory: 13088kb
input:
79999
output:
79482365
result:
ok 1 number(s): "79482365"