QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#589744#9309. GraphccpyWA 5ms9040kbC++141.7kb2024-09-25 19:59:032024-09-25 19:59:04

Judging History

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

  • [2024-09-25 19:59:04]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:9040kb
  • [2024-09-25 19:59:03]
  • 提交

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]<=mx;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++){
        if(i<=20) cout<<pri[i]<<endl;
        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));
            //cout<<w[j]<<" "<<g[j]<<endl;
        }
        //cout<<"~~~~~~~"<<endl;
    }
    // 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;
        //cout<<n/l<<" "<<w[k]<<endl;
        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: 0
Wrong Answer
time: 5ms
memory: 9040kb

input:

4

output:

2
3
5
7
11
13
17
19
23
29
31
37
41
43
47
53
59
61
67
71
8

result:

wrong answer expected '8', found '2'