QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#578533#9309. GraphNanani_fanTL 21ms28504kbC++173.5kb2024-09-20 19:51:252024-09-20 19:51:28

Judging History

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

  • [2024-09-20 19:51:28]
  • 评测
  • 测评结果:TL
  • 用时:21ms
  • 内存:28504kb
  • [2024-09-20 19:51:25]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define repd(i,l,r) for(int i=l;i>=r;--i)
using namespace std;
typedef long long ll;
#define int long long
const int N=1e6+100;
const int M=1e6+5;
const ll mod=998244353;
ll p[M];
int cnt;
ll getmi(ll x,ll y){
	ll ret=1;
	while(y){
		if(y&1) ret=ret*x%mod;
		x=x*x%mod;
		y=y>>1;
}
return ret;
}
const ll inv2=getmi(2,mod-2);
const ll inv4=getmi(4,mod-2);
const ll inv6=getmi(6,mod-2);
bitset<N> v;
void seive()
{
    for(int i=2;i<N;++i)
    {
        if(!v[i])
            p[++cnt]=i;
        for(int j=1;j<=cnt && i*p[j]<N;++j)
        {
            v[i*p[j]]=true;
            if(i%p[j]==0)
                break;
        }
    }
}
struct min25
{
    ll n,sum0[M],sum1[M],sum2[M],sum3[M];
    ll w[N<<1],g0[N<<1],g1[N<<1],g2[N<<1],g3[N<<1],G[N<<1];
    int id1[N],id2[N],tot,sq;
    ll calc(ll j,ll x)//f(p^x)的值 
	{
		return p[j]^x;
	}

    int getid(ll x)
    {
        if(x<=sq)
            return id1[x];
        return id2[n/x];
    }
    void init(ll nn)
    {
        for(int i=1;i<=cnt;++i)
        {
            sum0[i]=(sum0[i-1]+1)%mod;
            sum1[i]=(sum1[i-1]+p[i])%mod;
            sum2[i]=(sum2[i-1]+p[i]*p[i]%mod)%mod;
            sum3[i]=(sum3[i-1]+p[i]*p[i]%mod*p[i]%mod)%mod;
        }
        tot=0;
        n=nn;
        sq=sqrt(n);
        for(ll r,mm,m,l=1;l<=n;l=r+1)
        {
            r=n/(n/l);

            w[tot]=m=mm=n/l;
            mm%=mod;
            g0[tot]=(mm-1)%mod;
            g1[tot]=mm*(mm+1)%mod*inv2%mod-1;
            g2[tot]=mm*(mm+1)%mod*(2*mm%mod+1)%mod*inv6%mod-1;
            g3[tot]=mm*mm%mod*(mm+1)%mod*(mm+1)%mod*inv4%mod-1;
            if(m<=sq)
                id1[m]=tot;
            else
                id2[n/m]=tot;
            ++tot;
        }
        for(int i=1;i<=cnt;++i)
        {
            for(int j=0;j<tot && p[i]*p[i]<=w[j];++j)
            {
                ll t=getid(w[j]/p[i]);
                g0[j]=(g0[j]-(g0[t]-sum0[i-1])%mod)%mod;
                g1[j]=(g1[j]-p[i]*(g1[t]-sum1[i-1])%mod)%mod;
                g2[j]=(g2[j]-p[i]*p[i]%mod*(g2[t]-sum2[i-1])%mod)%mod;
                g3[j]=(g3[j]-p[i]*p[i]%mod*p[i]%mod*(g3[t]-sum3[i-1])%mod)%mod;
            }
        }
        rep(i,0,tot-1) G[i]=((g1[i]-g0[i])%mod+mod)%mod;//所有的K 均为calc(1) g[i]即质数的0次方和
		repd(j,cnt,1)
			rep(i,0,tot-1)
			{
				if((ll)p[j]*p[j]>w[i]) break;
				for(ll k=p[j],c=1; k*p[j]<=w[i]; ++c,k*=p[j],(G[i]+=(p[j]^c))%=mod)
					(G[i]+=(p[j]^c)%mod*(G[getid(w[i]/k)]-(g1[getid(p[j])]-g0[getid(p[j])])%mod+mod)%mod)%=mod;
			}

    }
    ll get(ll x)
	{
		return G[getid(x)]+1;
	}
    ll cal0(ll r)
    {
        return (g0[getid(r)])%mod;
    }
    ll cal1(ll r)
    {
        return (g1[getid(r)])%mod;
    }
    ll cal2(ll r)
    {
        return (g2[getid(r)])%mod;
    }
    ll cal3(ll r)
    {
        return (g3[getid(r)])%mod;
    }
}m2;
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    seive();
    ll n,ans=1;
    cin>>n;
    m2.init(n);
    for(int l=1,r=1;l<=n;l=r+1)
    {
        r=n/(n/l);
        int j=(n/l);
        auto cal=[&](int j)
        {
            if(j<=2) return (ll)1;
            if(j==3) return (ll)3;
            int gj=m2.cal0(j)-m2.cal0(j/2);
            return getmi(j%mod,gj%(mod-1))*(j-1-gj)%mod;
        };
        ans=ans*getmi(cal(j),(r-l+1))%mod;
    }
    cout<<(ans+mod)%mod<<"\n";
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 6ms
memory: 24860kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 4ms
memory: 26736kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 4ms
memory: 23228kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 4ms
memory: 28504kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 4ms
memory: 26764kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 4ms
memory: 25092kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 4ms
memory: 24956kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 0ms
memory: 26880kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 5ms
memory: 24900kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 11ms
memory: 28448kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 21ms
memory: 26828kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: -100
Time Limit Exceeded

input:

998244353

output:


result: