QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#574857#9309. GraphNTTTL 20ms11664kbC++231.2kb2024-09-19 03:06:352024-09-19 03:06:35

Judging History

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

  • [2024-09-19 03:06:35]
  • 评测
  • 测评结果:TL
  • 用时:20ms
  • 内存:11664kb
  • [2024-09-19 03:06:35]
  • 提交

answer

#pragma GCC optimize("Ofast,inline,unroll-loops")
#include<bits/stdc++.h>
using ll=long long;
constexpr int B=320000,M=998244353;
auto qpow(ll a,auto b){int res=1;for(;b;a=a*a%M,b>>=1)if(b&1)res=res*a%M;return res;}
int v[B],pi[B];
std::vector<int>prime;
ll n;
using Info=std::array<ll,2*B>;
auto&access(Info&a,ll x){
	if(x<=B)return a[x+B];
	return a[n/x];
}
signed main(){
	v[1]=1;
	for(int i=2;i<B;++i){
		pi[i]=pi[i-1];
		if(!v[i]){
			v[i]=i;
			++pi[i];
			prime.emplace_back(i);
		}
		for(auto&p:prime){
			if(i*p>=B)break;
			v[i*p]=p;
			if(v[i]==p)break;
		}
	}
	std::cin>>n;
	std::vector<ll>b;
	Info f={};
	for(ll l=1,r;l<=n;l=r+1){
		ll q=n/l;
		r=n/q;
		b.emplace_back(q);
		access(f,q)=q-1;
	}
	int lst=1;
	for(auto&p:prime){
		for(auto&x:b){
			if(p*p>x)break;
			access(f,x)-=access(f,x/p)-access(f,lst);
		}
		lst=p;
	}
	ll ans=1;
	for(ll l=1,r;l<=n;l=r+1){
		ll q=n/l;
		r=n/q;
		// std::cerr<<l<<' '<<r<<' '<<q<<'\n';
		ans=(ans*qpow([&]->ll{
			if(q==1)return 1;
			if(q==2)return 1;
			if(q==3)return 3;
			// int c=pi[q]-pi[q/2];
			ll c=access(f,q)-access(f,q/2);
			return qpow(q,c)*(q-c-1)%M;
		}()%M,r-l+1))%M;
	}
	printf("%lld\n",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 11432kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 5ms
memory: 11380kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 10ms
memory: 11320kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 20ms
memory: 11664kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: -100
Time Limit Exceeded

input:

145444

output:


result: