QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#567453#9309. GraphchsuhanWA 169ms91420kbC++14973b2024-09-16 12:04:232024-09-16 12:04:23

Judging History

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

  • [2024-09-16 12:04:23]
  • 评测
  • 测评结果:WA
  • 用时:169ms
  • 内存:91420kb
  • [2024-09-16 12:04:23]
  • 提交

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 (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: 169ms
memory: 89592kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 165ms
memory: 89864kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: -100
Wrong Answer
time: 166ms
memory: 91420kb

input:

123

output:

572189530

result:

wrong answer expected '671840470', found '572189530'