QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#578975#9309. GraphSSL_TJHTL 1403ms18184kbC++231.8kb2024-09-21 00:10:112024-09-21 00:10:11

Judging History

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

  • [2024-09-21 00:10:11]
  • 评测
  • 测评结果:TL
  • 用时:1403ms
  • 内存:18184kb
  • [2024-09-21 00:10:11]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define MOD 998244353
using namespace std;

typedef long long ll;

const ll MAXN=1e11;
const int N=1e6;
// SQRN is exactly floor(sqrt(n)), PNUM is the number of primes not greater than SQRN

ll POW(ll x, ll y) {
	ll re = 1;
	while (y) {
		if (y & 1) re = re * x % MOD;
		x = x * x % MOD; y >>= 1;
	}
	return re;
}

int p1,vt,z[N+5],pr[N+5];
long long n,x,v[N+5],f[2][N+5],s[N+5],g[N+5];
void dd(){
	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(){
	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){
	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;
}

ll quest(ll m) {
	n = m;
	init();
	return S(n,0);
}

int main() {
	dd();
	ll nn;
	scanf("%lld", &nn);
	
	if (nn == 2) {
		printf("1"); return 0;
	}
	if (nn == 3) {
		printf("3"); return 0;
	}
	
	ll re = 1;
	for (ll L = 1, R; L <= nn; L = R + 1) {
		R = nn / (nn / L);
		ll k = (nn / L) % MOD;
		if (k < 3) continue;
		if (k == 3) {
			(re *= POW(3, (R - L + 1))) %= MOD;
			continue;
		}
		ll awa = quest(k) - quest(k / 2);
		(re *= POW((k - awa - 1) % MOD * POW(k, awa % (MOD - 1)) % MOD, R - L + 1)) %= MOD;//k-awa-1: sz of the block where 2 in 
	}
	printf("%lld", re);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 9ms
memory: 18052kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 23ms
memory: 18052kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 85ms
memory: 18036kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 115ms
memory: 17844kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 270ms
memory: 17932kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 280ms
memory: 17916kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 1403ms
memory: 18184kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: -100
Time Limit Exceeded

input:

102850434

output:

604886751

result: