QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#567465#9309. GraphchsuhanWA 147ms91112kbC++14975b2024-09-16 12:08:402024-09-16 12:08:41

Judging History

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

  • [2024-09-16 12:08:41]
  • 评测
  • 测评结果:WA
  • 用时:147ms
  • 内存:91112kb
  • [2024-09-16 12:08:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=10000007,P=998244353;
unordered_map<int,int>mp;
int n,sp[N];
vector<int>p;
int pw(int x,int y){
	int z=1;
	x%=P;
	for(;y;y>>=1){
		if(y&1)z=z*x%P;
		x=x*x%P;
	}
	return z;
}
int sp_(int x){
	if(x<N)return sp[x];
	return mp[x];
}
void getsp(){
	for(int i=1;p[i]*p[i]<=n;i++)
		for(int j=n;j>=p[i]*p[i];j=n/(n/j+1)){
			if(j<N)sp[j]-=sp_(j/p[i])-sp[p[i-1]];
			else mp[j]-=sp_(j/p[i])-sp[p[i-1]];
//			cout<<j<<'\n';
		}
}
int f(int x){
	if(x<=2)return 1;
	int m=sp_(x)-sp_(x/2)+2;
	return (n-m+1)*pw(x,m-2)%P;
}
signed main(){
	cin>>n;
	p.push_back(1);
	for(int i=2;i<N;i++){
		if(sp[i])continue;
		p.push_back(i);
		for(int j=i*i;j<N;j+=i)sp[j]=1;
	}
	for(int i=n;i>1;i=n/(n/i+1)){
		if(i<N)sp[i]=i-1;
		else mp[i]=i-1;
	}
	getsp();
	int ans=1;
	for(int l=1,r;l<=n;l=r+1){
		r=n/(n/l);
		ans=ans*pw(f(n/l),r-l+1)%P;
	}
	cout<<ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 132ms
memory: 91112kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 134ms
memory: 90168kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: -100
Wrong Answer
time: 147ms
memory: 90024kb

input:

123

output:

765862896

result:

wrong answer expected '671840470', found '765862896'