QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#602190#9309. GraphlaurxhWA 3ms17800kbC++141.5kb2024-09-30 20:51:452024-09-30 20:51:46

Judging History

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

  • [2024-09-30 20:51:46]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:17800kb
  • [2024-09-30 20:51:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+7;
const int mod=998244353;
ll n,tot,cnt,len;
int vis[N],prime[N];
ll g[N],w[N],idx1[N],idx2[N];
void seive(){
    for(int i=2;i<N;i++){
        if(!vis[i])prime[++tot]=i;
        for(int j=1;j<=tot&&1ll*i*prime[j]<N;j++){
            vis[i*prime[j]]=1;
            if(i%prime[j]==0)break;
        }
    }
}
ll kuasum(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1)ans=ans*a%mod;
        b>>=1;
        a=a*a%mod;
    }
    return ans;
}
ll get_id(ll x){
    return (x<=len?idx1[x]:idx2[n/x]);
}
ll get(ll x){
    return g[get_id(x)];
}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
    seive();
    cin>>n;
    len=sqrt(n);
    for(ll l=1,r;l<=n;l=r+1){
        r=n/(n/l);ll x=n/l;w[++cnt]=x;
        g[cnt]=x-1; 
        if(w[cnt]<=len)idx1[w[cnt]]=cnt;
        else idx2[n/w[cnt]]=cnt;     
    }
    for(int i=1;i<=tot;i++){
        for(int j=1;j<=cnt&&1ll*prime[i]*prime[i]<=w[j];j++){
            int x=prime[i],r=w[j]/x;
            int k=get_id(r);
            g[j]-=g[k]-(i-1);
        }
    }
    ll ans=1;
    for(ll l=1,r;l<=n;l=r+1){
        ll x=n/l;
        r=n/x;
        if(x==1)continue;
        ll sum=get(x)-get(x/2)+1;
        ll num=sum+(x!=sum);
        ll res=kuasum(x%mod,num-2);
        if(x!=sum)res=res*(x-sum)%mod;
        // cout<<sum<<" "<<res<<"\n";
        ans=ans*kuasum(res,r-l+1);
    }  
    cout<<ans<<"\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 17800kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 3ms
memory: 15728kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: -100
Wrong Answer
time: 3ms
memory: 15808kb

input:

123

output:

0

result:

wrong answer expected '671840470', found '0'