QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#573006#9309. GraphOIer_kzcAC ✓2174ms25760kbC++142.3kb2024-09-18 17:03:122024-09-18 17:03:13

Judging History

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

  • [2024-09-18 17:03:13]
  • 评测
  • 测评结果:AC
  • 用时:2174ms
  • 内存:25760kb
  • [2024-09-18 17:03:12]
  • 提交

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 vs[N]; int szv;
LL g[N];

int id(LL v) {
	int k = lower_bound(vs, vs + szv, v) - vs;
	if (k < 0 || k >= szv || vs[k] != v) {
		LOG("ERR\n");
		while (true);
	}
	return k;
}

void min25(LL n) {
	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();
	LL n;
	scanf("%lld", &n);
	min25(n);
	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,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 11956kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 7ms
memory: 11988kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 7ms
memory: 11992kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 7ms
memory: 11968kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 4ms
memory: 13644kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 12ms
memory: 11912kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 8ms
memory: 12036kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 19ms
memory: 13804kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

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

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 91ms
memory: 12972kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

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

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 156ms
memory: 15280kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 277ms
memory: 18808kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

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

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 1396ms
memory: 20584kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 1961ms
memory: 23612kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 2151ms
memory: 24304kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 2156ms
memory: 24244kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 2174ms
memory: 25760kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed