QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#589707 | #9309. Graph | ccpy | WA | 4ms | 11680kb | C++14 | 1.5kb | 2024-09-25 19:48:34 | 2024-09-25 19:48:35 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000005
using namespace std;
const ll mod=998244353;
ll qm(ll x){
if(x>=mod) x-=mod;
return x;
}
ll fpow(ll a,ll b){
ll r=1;
while(b){
if(b&1) r=r*a%mod;
a=a*a%mod;b>>=1;
}
return r;
}
int pri[MAX],cnt;
bool vis[MAX];
void init(){
int mx=1000000;
for(int i=2;i<=mx;i++){
if(!vis[i]) pri[++cnt]=i;
for(int j=1;j<=cnt&&i*pri[j]<=i;j++){
vis[i*pri[j]]=1;
if(i%pri[j]==0) break;
}
}
}
ll n,m;
int id1[MAX],id2[MAX],tot;
int id(ll x){
if(x<=m) return id1[x];
return id2[n/x];
}
ll w[MAX];
ll g[MAX];
int main(){
init();
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n;m=sqrt(n);
for(ll l=1,r;l<=n;l=r+1){
w[++tot]=n/l;
r=n/(n/l);
g[tot]=w[tot]-1;
if(w[tot]<=m) id1[w[tot]]=tot;
else id2[n/w[tot]]=tot;
}
for(int i=1;i<=cnt;i++){
for(int j=1;j<=tot&&1ll*pri[i]*pri[i]<=w[j];j++){
int k=id(w[j]/pri[i]);
g[j]-=(g[k]-(i-1));
}
}
//for(int i=1;i<=tot;i++){
// cout<<i<<" "<<w[i]<<" "<<g[i]<<endl;
//}
ll ans=1;
for(ll l=1,r;l<=n;l=r+1){
int k=id(n/l);
r=n/(n/l);
ll tp=g[id(n/l)]-g[id(n/l/2)]+1;
ll rs=w[k]-tp;
ll sm=1;
if(tp+(rs>0)>1) sm=(rs?rs:1ll)*fpow(w[k],tp+(rs>0)-2)%mod;
//cout<<sm<<endl;
ans=ans*fpow(sm,r-l+1)%mod;
}
cout<<ans;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11676kb
input:
4
output:
8
result:
ok answer is '8'
Test #2:
score: 0
Accepted
time: 0ms
memory: 11680kb
input:
2
output:
1
result:
ok answer is '1'
Test #3:
score: -100
Wrong Answer
time: 4ms
memory: 11596kb
input:
123
output:
462197909
result:
wrong answer expected '671840470', found '462197909'