QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#601356#9309. GraphAshbourneWA 40ms19260kbC++141.6kb2024-09-29 22:30:282024-09-29 22:30:28

Judging History

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

  • [2024-09-29 22:30:28]
  • 评测
  • 测评结果:WA
  • 用时:40ms
  • 内存:19260kb
  • [2024-09-29 22:30:28]
  • 提交

answer

#include<bits/stdc++.h> 
using namespace std;
#define int long long
#define rep(i, j, k) for(int i = j; i <= k; ++ i)
#define drp(i, j, k) for(int i = j; i >= k; -- i)
const int N = 4e5 + 10, Mod = 998244353;
int fpow(int a, int b){
	int x = 1;
	while(b){
		if(b & 1) x = x * a % Mod;
		a = a * a % Mod;
		b >>= 1;
	}
	return x;
}
int inv2;
int pri[N], ispri[N], b[N][2], c[N], g[N], w[N], P, E;
void prpr(int n){
	inv2 = fpow(2, Mod - 2);
	rep(i, 1, n) ispri[i] = 1;
	rep(i, 2, n){
		if(ispri[i]){
			pri[++P] = i;
			c[P] = (c[P - 1] + 1);
		}
		rep(j, 1, P){
			if(i * pri[j] > n) break;
			ispri[i * pri[j]] = 0;
			if(i % pri[j] == 0) break;
		}
	}
}
int ans = 1, z[N];
#define id(x) (x <= E ? b[x][0]: b[n / (x)][1])
void calc(int n){
	E = sqrt(n);
	int t = 0, l = 1, r, q;
	for(; l <= n; l = r + 1){
		q = w[id(n / l) = ++ t] = n / l; r = (n / q);
		z[t] = (r - l + 1);
		int num = w[t] % Mod;
		g[t] = num + Mod - 1;
		g[t] %= Mod;
		// g[t] = (g[t] + Mod - 1) % Mod;
	}
	// rep(i, 1, t) cout << g[i] << endl;
	// t--;
	rep(i, 1, P) rep(j, 1, t){
		if(pri[i] * pri[i] > w[j]) break;
		q = id(w[j] / pri[i]);
		g[j] = (g[j] - g[q] + c[i - 1] + Mod) % Mod;
	}
	rep(i, 1, t){
		q = id(w[i] / 2);
		g[i] = (g[i] - g[q] + Mod) % Mod;
	}
	// rep(i, 1, t) cout << g[i] << endl;
	rep(i, 1, t - 1){
		int m = w[i];
		int f_tt = (m - g[i] - 1) * fpow(m, g[i]) % Mod;
		if(f_tt == 0) f_tt = fpow(m, g[i] - 1) % Mod;
		// cout << f_tt << endl;
		ans = ans * fpow(f_tt, z[i]) % Mod;
	}
	cout << ans << endl;
}
signed main(){
	ios::sync_with_stdio(0);
	prpr(4e5);
	int n; cin >> n;
	calc(n);
	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

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

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 17ms
memory: 15108kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 17ms
memory: 17016kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

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

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: -100
Wrong Answer
time: 40ms
memory: 17536kb

input:

5120103302

output:

406301251

result:

wrong answer expected '116870489', found '406301251'