QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#208920#4478. Jo loves countinglhzawaWA 1807ms37628kbC++141.6kb2023-10-09 22:04:512023-10-09 22:04:52

Judging History

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

  • [2023-10-09 22:04:52]
  • 评测
  • 测评结果:WA
  • 用时:1807ms
  • 内存:37628kb
  • [2023-10-09 22:04:51]
  • 提交

answer

#include<bits/stdc++.h>
using LL = long long;
using LLL = __int128;
constexpr LL mod = 29LL << 57 | 1LL;
constexpr LL M(LL a, LL b) {
	a %= mod, b %= mod;
	return LLL(a) * LLL(b) % mod;
}
constexpr LL J(LL a, LL b) {
	a %= mod, b %= mod;
	return a >= b ? a - b : mod + a - b; 
}
constexpr LL qpow(LL a, LL b) {
	a %= mod;
	LL v = 1;
	for (; b; b >>= 1, a = M(a, a))
		if (b & 1) v = M(v, a);
	return v;
}
constexpr LL inv2 = qpow(2LL, mod - 2);
const int maxm = 1e6, maxp = 78948;
const LL maxn = LL(1e12);
int m;
int p[maxm + 1];
LL h[maxp + 1][42];
LL n;
LL ans;
void dfs(int w, LL x, LL v) {
	printf("%d %lld\n", w, x);
	if (w > m || x * p[w] > n || x * p[w] * p[w] > n) {
		ans = (ans + M(v, M(M(n / x, n / x + 1), inv2))) % mod;
		return ;
	}
	dfs(w + 1, x, v);
	x *= 1LL * p[w] * p[w];
	for (int i = 2; x <= n; x *= p[w], i++) dfs(w + 1, x, M(v, h[w][i]));
}
std::bitset<maxm + 1> vis;
LL inv[42];
int main() {
	inv[1] = 1LL;
	for (int i = 2; i < 42; i++) inv[i] = M(mod - mod / i, inv[mod % i]);
	for (int i = 2; i <= maxm; i++) {
		if (! vis[i]) {
			p[++m] = i;
			h[m][0] = 1LL, h[m][1] = 0LL;
			LL x = 1LL * i * i;
			LL fv = M(x, inv2), ghv = x;
			for (int j = 2; x <= maxn; j++, x *= i) {
				h[m][j] = J(fv, ghv), fv = M(fv, M(M(j, i), inv[j + 1])), ghv = M((ghv + h[m][j]) % mod, i) % mod;
			} 
		}
		for (int j = 1; j <= m && i * p[j] <= maxm; j++) {
			vis[i * p[j]] = 1;
			if (i % p[j] == 0) break;
		}
	}
	int T;
	scanf("%d", &T);
	for (; T; T--) {
		scanf("%lld", &n);
		ans = 0;
		dfs(1, 1LL, 1LL);
		printf("%lld\n", M(ans, qpow(n, mod - 2)));
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1807ms
memory: 37628kb

input:

12
4
959139
9859
125987
209411
965585325539
213058376259
451941492387
690824608515
934002691939
1000000000000
1

output:

1 1
2 1
2 4
2
1 1
2 1
3 1
4 1
5 1
6 1
7 1
8 1
9 1
10 1
11 1
12 1
13 1
14 1
15 1
16 1
17 1
18 1
19 1
20 1
21 1
22 1
23 1
24 1
25 1
26 1
27 1
28 1
29 1
30 1
31 1
32 1
33 1
34 1
35 1
36 1
37 1
38 1
39 1
40 1
41 1
42 1
43 1
44 1
45 1
46 1
47 1
48 1
49 1
50 1
51 1
52 1
53 1
54 1
55 1
56 1
57 1
58 1
59 1
...

result:

wrong answer 1st lines differ - expected: '2', found: '1 1'