QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#577194#9309. GraphLOOP0RE 15ms19952kbC++141.2kb2024-09-20 09:00:122024-09-20 09:00:12

Judging History

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

  • [2024-09-20 09:00:12]
  • 评测
  • 测评结果:RE
  • 用时:15ms
  • 内存:19952kb
  • [2024-09-20 09:00:12]
  • 提交

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;
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;
		}
	}
}
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;
}
long long ans(long long n){
    if(n<=2) return 1;
    int cnt=1;
    for(int i=n/2+1;i<=n;++i){
        if(!z[i]) ++cnt;
    }
    int res=n-cnt;
    if(res==0){
        return fpow(n%mod,cnt-2);
    }
    else{
        return fpow(n%mod,cnt-1)*(res%mod)%mod;
    }
}
long long calc(long long n){
    long long a=1;
    for(int i=1;i<=n;++i){
        long long tp=ans(n/i);
        //printf("ans(%lld)=%lld\n",n/i,tp);
        a=(a*tp)%mod;
    }
    return a;
}
signed main()
{
    long long n;
    dd();
    scanf("%lld",&n);
	if(n==1){
        printf("1\n");
    }
    else{
        printf("%lld\n",calc(n));
    }
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 7ms
memory: 17752kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 7ms
memory: 17840kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 7ms
memory: 19952kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 7ms
memory: 17828kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 15ms
memory: 17832kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: -100
Runtime Error

input:

23333333

output:


result: