QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#577212#9309. GraphGricewTL 1821ms26580kbC++142.0kb2024-09-20 09:12:592024-09-20 09:12:59

Judging History

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

  • [2024-09-20 09:12:59]
  • 评测
  • 测评结果:TL
  • 用时:1821ms
  • 内存:26580kb
  • [2024-09-20 09:12:59]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1000000;
int p1,vt,z[N+5],pr[N+5];
long long x,v[N+5],f[2][N+5],s[N+5],g[N+5];
const signed mod=998244353;
long long fpow(long long a,int b){
    long long ans=1;
    while(b){
        if(b&1) ans=ans*a%mod; 
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
void dd(){
    p1=0;
    for(int i=2;i<=N;i++){
        if(!z[i]){
            pr[++p1]=i;
            s[p1]=p1;
        }
        for(int j=1;j<=p1&&i*pr[j]<=N;j++){
            z[i*pr[j]]=1;
            if(i%pr[j]==0) break;
        }
    }
}
void init(long long n){
    x=sqrt(n)+1;
    vt=0;
    for(long long l=1,r;l<=n;l=r+1){
        r=n/(n/l);
        v[++vt]=n/l;
        if(n/l<=x) f[0][n/l]=vt;
        else f[1][l]=vt;
        long long t=n/l;
        g[vt]=t-1;
    }
    long long w;
    for(int i=1;i<=p1 && pr[i]*pr[i]<=n;i++){
        w=1ll*pr[i]*pr[i];
        long long t;
        for(int j=1;j<=vt&&w<=v[j];j++){
            t=v[j]/pr[i];
            if(t<=x) t=f[0][t];
            else t=f[1][n/t];
            g[j]-=g[t]-s[i-1];
        }
    }
    
}
long long S(long long p,int q,long long n){
    if(pr[q]>=p) return 0;
    long long td=(p<=x?f[0][p]:f[1][n/p]);
    long long re=g[td]-s[q];
    return re;
}
long long calc(long long n){
    init(n);
    return S(n,0,n);
}
long long ans(long long n){
    if(n<=2) return 1;
    long long cnt=calc(n)-calc(n/2)+1;
    long long res=n-cnt;
    if(res==0){
        return fpow(n%mod,cnt-2);
    }else{
        return fpow(n%mod,cnt-1)*(res%mod)%mod;
    }
}
long long solve(long long n){
    long long a=1;
    for(int l=1;l<=n;++l){
    	long long r(n/(n/l));
    	a=a*fpow(ans(n/l),r-l+1)%mod;
    	l=r;
    }
    return a;
}
signed main()
{
    long long n;
    dd();
    scanf("%lld",&n);
    if(n==1){
        printf("1\n");
    }
    else{
        printf("%lld\n",solve(n));
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 8ms
memory: 23896kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 6ms
memory: 23900kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 9ms
memory: 21820kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 88ms
memory: 22068kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 288ms
memory: 24112kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 1820ms
memory: 22480kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 1821ms
memory: 26580kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: -100
Time Limit Exceeded

input:

2147483547

output:


result: