QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#694030#9309. GraphWuyanruWA 1ms5948kbC++142.2kb2024-10-31 17:08:332024-10-31 17:08:38

Judging History

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

  • [2024-10-31 17:08:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5948kb
  • [2024-10-31 17:08:33]
  • 提交

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);
    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;
    if(m==1) return 1;
    if(v==m) return qow(m,m-2);
    //共 v 个孤立点和 1 个连通块
    // printf("m=%lld v=%lld\n",m,v);
    return qow(m,v-1)*(m-v)%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=0;
    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);
    }
    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);
    }

    // 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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 5904kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5880kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 5948kb

input:

123

output:

887314082

result:

wrong answer expected '671840470', found '887314082'