QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#669021 | #9309. Graph | Folity | WA | 2ms | 13784kb | C++20 | 1.1kb | 2024-10-23 17:02:22 | 2024-10-23 17:02:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e5+3,mod=998244353;
int cnt=0;
ll pri[N];
bool np[N];
void sieve(int n){
np[1]=1;
for(int i=2;i<=n;++i){
if(!np[i])pri[++cnt]=i;
for(int j=1;j<=cnt&&i*pri[j]<=n;++j){
np[i*pri[j]]=1;
if(!(i%pri[j]))break;
}
}
}
int tot=0;
ll n,q,buc[N*2],g[N*2],i1[N],i2[N];
inline ll S(ll x){
return x<=q?g[i1[x]]:g[i2[n/x]];
}
ll qpow(ll x,ll y){
x%=mod,y%=mod-1;
ll r=1;
for(;y;y>>=1){
if(y&1)r=r*x%mod;
x=x*x%mod;
}
return r;
}
int main(){
cin>>n;
q=sqrt(n);
sieve(q);
for(ll i=1,j;i<=n;i=j+1){
j=n/(n/i);
buc[++tot]=n/i;
g[tot]=buc[tot]-1;
if(n/i<=q)i1[n/i]=tot;
else i2[n/(n/i)]=tot;
}
for(int i=1;i<=cnt;++i)
for(int j=1;j<=tot&&pri[i]*pri[i]<=buc[j];++j){
ll t=buc[j]/pri[i];
ll k=t<=q?i1[t]:i2[n/t];
g[j]-=g[k]-i+1;
}
ll ans=1,w,t;
for(ll i=1,j,m;i<=n/3;i=j+1){
m=n/i,j=n/m;
w=S(m)-S(m/2)+2;
t=(m-w+1)%mod*qpow(m,w-2)%mod;
ans=ans*qpow(t,j-i+1)%mod;
}
cout<<ans<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11692kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 2ms
memory: 11844kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 13784kb
input:
123
output:
0
result:
wrong answer expected '671840470', found '0'