QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#577223#9309. GraphGricewAC ✓309ms38432kbC++142.0kb2024-09-20 09:24:042024-09-20 09:24:07

Judging History

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

  • [2024-09-20 09:24:07]
  • 评测
  • 测评结果:AC
  • 用时:309ms
  • 内存:38432kb
  • [2024-09-20 09:24:04]
  • 提交

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;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 p,long long n){
	if(p<=1) return 0;
    return S(p,0,n);
}
long long ans(long long n,long long _n){
    if(n<=2) return 1;
    long long cnt=calc(n,_n)-calc(n/2,_n)+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,n),r-l+1)%mod;
    	l=r;
    }
    return a;
}
signed main()
{
    long long n;
    scanf("%lld",&n);
    dd();
    init(n);
    if(n==1){
        printf("1\n");
    }
    else{
        printf("%lld\n",solve(n));
    }
    return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 9ms
memory: 23860kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 2ms
memory: 21848kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 2ms
memory: 23956kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 8ms
memory: 21852kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 8ms
memory: 24172kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 19ms
memory: 22424kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 19ms
memory: 22308kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 24ms
memory: 28772kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 46ms
memory: 28916kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 104ms
memory: 28512kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 195ms
memory: 33264kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 271ms
memory: 35444kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 307ms
memory: 38236kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 301ms
memory: 38432kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 309ms
memory: 38100kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed