QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#572838#9309. Graph000226AC ✓299ms27652kbC++172.4kb2024-09-18 16:34:002024-09-18 16:34:01

Judging History

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

  • [2024-09-18 16:34:01]
  • 评测
  • 测评结果:AC
  • 用时:299ms
  • 内存:27652kb
  • [2024-09-18 16:34:00]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define lep(i, l, r) for(int i = (l); i <= (r); i ++)
#define rep(i, l, r) for(int i = (l); i >= (r); i --)
#define Lep(i, l, r) for(int i = (l); i <  (r); i ++)
#define debug(...) fprintf (stderr, __VA_ARGS__)
//#define int long long
using i64 = long long;
using ld = long double;
using ui64 = unsigned long long;

const int P = 998244353;
inline int mod(int x) { return x + (x >> 31 & P); }
inline void pls(int &x, int y) { x = mod(x + y - P); }
inline void sub(int &x, int y) { x = mod(x - y); }
inline int  add(int x, int y) { return mod (x + y - P); }
inline int  dec(int x, int y) { return mod (x - y); }

inline int power(i64 x, i64 k) {
	int res = 1;
	while(k) {
		if (k & 1) res = 1ll * res * x % P;
		x = 1ll * x * x % P; k >>= 1;
	} return res;
}

namespace Min25 {

	#define LL long long

	LL n;

	const int N = 1e6 + 10;

	int vis[N], p[N], tot;

	void init(int n = 1e6) {
		for(int i = 2; i <= n; i ++) {
			if(! vis[i]) p[++ tot] = i;
			for(int j = 1; p[j] * i <= n && j <= tot; j ++) {
				vis[i * p[j]] = 1;
				if(i % p[j] == 0) break;
			}
		}
	}

	int id0[N], id1[N];
	LL val[N];
	int num, sqr;
	LL g[N];

	inline int pos(LL x) {
		if(x <= sqr) return id0[x];
		else return id1[n / x];
	}

	i64 qry (i64 x) {
		if (x == 0) return 0;
		if (x <= sqr) return g[id0[x]];
		else return g[id1[n / x]];
	}

	void main(i64 _n) {
		
		n = _n;
		sqr = sqrt(n) + 1;
		init(sqr);
		for(LL l = 1, r = 1; l <= n; l = r = r + 1) {
			LL tmp = n / l;
			r = n / tmp;
			val[++ num] = tmp;
			if(tmp <= sqr) id0[tmp] = num;
			else id1[n / tmp] = num;
		}
		for(int i = 1; i <= num; i ++) g[i] = val[i] - 1;
		
		for(int j = 1; j <= tot; j ++) {
			int pj = p[j];
			for(int i = 1; i <= num; i ++) {
				if(val[i] / pj < pj) break;
				g[i] = g[i] - g[pos(val[i] / pj)] + j - 1;
			}
		}
		
		//cout << g[1] << endl;
		//return 0;
	}
}

i64 n;

inline int f(i64 m) {
	if (m <= 2) return 1;
	if (m == 3) return 3;
	// calc [m / 2 + 1, m]
	i64 cnt = Min25 :: qry(m) - Min25 :: qry(m / 2);
	
	return 1ll * (m - cnt - 1) % P * power (m % P, cnt) % P;
}

signed main() {
	ios :: sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n;
	Min25 :: main(n);
	i64 ans = 1;
	for (i64 l = 1, r; l <= n; l = r + 1) {
		r = n / (n / l);
		ans = 1ll * ans * power (f(n / l), r - l + 1) % P;
	}
	cout << ans << '\n';
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 9944kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 1ms
memory: 7736kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

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

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 15ms
memory: 10540kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 16ms
memory: 14064kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 21ms
memory: 12856kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 38ms
memory: 13300kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 90ms
memory: 18228kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 183ms
memory: 22528kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 268ms
memory: 23376kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 299ms
memory: 23344kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 293ms
memory: 23896kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 296ms
memory: 27652kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed