QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#573022#9309. GraphOIer_kzcAC ✓320ms24648kbC++142.3kb2024-09-18 17:05:382024-09-18 17:05:38

Judging History

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

  • [2024-09-18 17:05:38]
  • 评测
  • 测评结果:AC
  • 用时:320ms
  • 内存:24648kb
  • [2024-09-18 17:05:38]
  • 提交

answer

#include <math.h>
#include <stdio.h>
#include <string.h>

#include <vector>
#include <algorithm>
#include <unordered_map>

#define LOG(FMT...) fprintf(stderr, FMT)

#define eb emplace_back

using namespace std;

typedef long long LL;
constexpr int N = 2000005, PC = 271234;
constexpr int mod = 998244353;

char gc() {
	static char buf[1 << 21], *p1 = buf, *p2 = buf;
	return (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? -1 : *p1++);
}
int read() {
	int x = 0; char c = gc();
	while (c < 48 || c > 57) {
		c = gc();
	}
	for (; c > 47 && c < 58; c = gc()) {
		x = x * 10 + (c ^ 48);
	}
	return x;
}

int pr[PC], cnt;
bool was[N];
int c[N];

void sieve() {
	for (int x = 2; x < N; ++x) {
		if (!was[x]) {
			pr[cnt++] = x;
		}
		for (int k = 0; x * pr[k] < N; ++k) {
			was[x * pr[k]] = true;
			if (!(x % pr[k])) {
				break;
			}
		}
	}
	for (int i = 2; i < N; ++i) {
		c[i] = c[i - 1] + !was[i];
	}
}

constexpr int inv(int x, int k = mod - 2) {
	int r = 1;
	while (k) {
		if (k & 1) {
			r = x * (LL)r % mod;
		}
		x = x * (LL)x % mod;
		k >>= 1;
	}
	return r;
}

LL sqr(int x) {
	return x * (LL)x;
}

LL n, Br;
LL vs[N]; int szv;
LL g[N];

int id(LL v) {
	int k = (v <= Br ? v - 1 : szv - n / v);
	if (k < 0 || k >= szv || vs[k] != v) {
		LOG("ERR %d %lld %lld\n", k, vs[k], v);
		while (true);
	}
	return k;
}

void min25() {
	for (LL l = 1, r; l <= n; l = r + 1) {
		r = n / (n / l);
		vs[szv++] = n / r;
	}
	reverse(vs, vs + szv);
	for (int i = 0; i < szv; ++i) {
		g[i] = vs[i] - 1;
	}
	LL B;
	for (int i = 0; (B = sqr(pr[i])) <= n; ++i) {
		for (int j = szv - 1; vs[j] >= B; --j) {
			g[j] += i - g[id(vs[j] / pr[i])];
		}
	}
}

LL calc(LL x) {
	return g[id(x)];
}

constexpr int f(LL x) {
	if (x == 1) {
		return 1;
	}
	if (x == 2) {
		return 1;
	}
	if (x == 3) {
		return 3;
	}
	LL y = calc(x) - calc(x / 2);
	return (x - y - 1) % mod * inv(x % mod, y % (mod - 1)) % mod;
}

int main() {
	// LOG("%.3lf\n", (sizeof c + sizeof was + sizeof pr) / 1048576.0);
	sieve();
	scanf("%lld", &n);
	Br = sqrtl(n);
	min25();
	int res = 1;
	for (LL l = 1, r; l <= n; l = r + 1) {
		r = n / (n / l);
		res = res * (LL)inv(f(n / r), (r - l + 1) % (mod - 1)) % mod;
	}
	printf("%d\n", res);
	return 0;
}

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

详细

Test #1:

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

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 11ms
memory: 12304kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 11ms
memory: 12412kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 11ms
memory: 12420kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 11ms
memory: 12364kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 11ms
memory: 12316kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 11ms
memory: 12332kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 11ms
memory: 12412kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

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

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

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

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 22ms
memory: 13280kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

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

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 45ms
memory: 17176kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 99ms
memory: 18928kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 206ms
memory: 22724kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 281ms
memory: 24564kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 316ms
memory: 23936kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 320ms
memory: 23948kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 303ms
memory: 24648kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed