QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#578974#9309. GraphSSL_TJHTL 1401ms20212kbC++141.7kb2024-09-21 00:08:392024-09-21 00:08:39

Judging History

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

  • [2024-09-21 00:08:39]
  • 评测
  • 测评结果:TL
  • 用时:1401ms
  • 内存:20212kb
  • [2024-09-21 00:08:39]
  • 提交

answer

#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: 3ms
memory: 20108kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 6ms
memory: 18088kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 27ms
memory: 17848kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 80ms
memory: 17976kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 107ms
memory: 18064kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 267ms
memory: 20156kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 285ms
memory: 18068kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 1401ms
memory: 20212kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: -100
Time Limit Exceeded

input:

102850434

output:

604886751

result: