QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694099#9309. GraphWuyanruRE 1ms5828kbC++142.3kb2024-10-31 17:16:192024-10-31 17:16:19

Judging History

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

  • [2024-10-31 17:16:19]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5828kb
  • [2024-10-31 17:16:19]
  • 提交

answer

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3fll
#define debug(x) cerr<<#x<<"="<<x<<endl
using namespace std;
using ll=long long;
using ld=long double;
using pli=pair<ll,int>;
using pi=pair<int,int>;
template<typename A>
using vc=vector<A>;
inline int read()
{
    int s=0,w=1;char ch;
    while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}
inline ll lread()
{
    ll s=0,w=1;char ch;
    while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}
const int mod=998244353;
int pri[400005];
bool is[400005];
ll f1[400005];
ll f2[400005];
ll sq,n;
inline ll G(ll n,int k)
{
    if(!k) return n-1;
    if(n==1) return 0;
    ll ans=G(n,k-1);
    if((ll)pri[k]*pri[k]<=n) ans-=G(n/pri[k],k-1)-(k-1);
    return ans;
}
inline ll qow(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
inline ll fp(ll w)
{
    if(w<=sq) return f1[w];
    return f2[n/w];
}
inline ll get(ll m)
{
    ll v=fp(m)-fp(m/2)+1;
    v=(v%mod+mod)%mod;
    if(m==1) return 1;
    if(v==m) return qow(m%mod,m-2);
    //共 v 个孤立点和 1 个连通块
    // printf("m=%lld v=%lld\n",m,v);
    return (m-v)%mod*qow(m%mod,v-1)%mod;
}
int main()
{
    n=read();
    for(;(sq+1)*(sq+1)<=n;sq++);

    for(int i=2;i<=sq;i++)
    {
        if(!is[i]) pri[++pri[0]]=i;
        for(int j=1;j<=pri[0]&&i*pri[j]<=n;j++)
        {
            is[i*pri[j]]=1;
            if(i%pri[j]==0) break;
        }
    }
    // printf("??\n");
    int k=1;
    for(int i=1;i<=sq;i++)
    {
        ll lim=i;
        while(k<pri[0]&&(ll)pri[k+1]*pri[k+1]<=lim) k++;
        f1[i]=G(lim,k)%mod;
    }
    for(int i=sq;i;i--)
    {
        ll lim=n/i;
        while(k<pri[0]&&(ll)pri[k+1]*pri[k+1]<=lim) k++;
        f2[i]=G(lim,k)%mod;
    }
    // debug(G(11,2));
    // debug(G(3,1)-G(2,1));
    // for(ll i=1;i<=n;i++) if(i==1||n/i!=n/(i+1)) printf("%lld : %lld\n",n/i,fp(n/i));

    ll ans=1;
    for(ll l=1,r;l<=n;l=r+1)
    {
        r=n/(n/l);
        // printf("l=%lld r=%lld\n",l,r);
        ans=ans*qow(get(n/l),r-l+1)%mod;
        // printf("ans=%lld\n",ans);
    }
    printf("%lld\n",ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5828kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: -100
Runtime Error

input:

2

output:


result: