QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#497318 | #3295. 循环之美 | feecle6418 | 100 ✓ | 18ms | 7780kb | C++17 | 1.6kb | 2024-07-28 22:50:55 | 2024-07-28 22:50:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int s1[2005], is[2005], n, m, K, f[200005], a[200005], g[200005], tot;
int p[200005], cnt, s2[2005], sq, fir1[40005], fir2[40005];
double inv[200005];
int pos(int u) {
if (u <= sq) return u;
int x = n / u, y = m / u;
return max(fir1[x], fir2[y]);
}
ll F(ll x) { return (x / K) * s1[K] + s1[x % K]; }
int main() {
cin >> n >> m >> K, sq = sqrt(max(n, m));
for (int i = 1; i <= K; i++) {
s1[i] = s1[i - 1] + (is[i] = (gcd(i, K) == 1));
s2[i] = s2[i - 1];
if (i > 1 && K % i == 0) {
bool ok = 1;
for (int j = 2; j * j <= i; j++)
if (i % j == 0) ok = 0;
s2[i] += ok;
}
}
int P = min(n, m);
for (int i = 1, j; i <= P; i = j + 1) {
j = min(n / (n / i), m / (m / i));
a[++tot] = j, g[tot] = j - 1;
if (j <= sq) continue;
if (!fir1[n / i]) fir1[n / i] = tot;
if (!fir2[m / i]) fir2[m / i] = tot;
}
for (int i = 2; i * i <= P; i++) {
if (g[i] == g[i - 1]) continue;
p[++cnt] = i, inv[cnt] = 1.00000000000001 / i;
for (int j = tot; a[j] >= i * i; j--) {
g[j] -= g[pos(a[j] * inv[cnt])] - cnt + 1;
}
}
for (int i = 1; i <= tot; i++) {
f[i] = -g[i] + s2[min(K, a[i])];
}
for (int i = cnt; i; i--) {
if (K % p[i] == 0) continue;
for (int j = tot; a[j] >= p[i] * p[i]; j--) {
int u = pos(a[j] * inv[i]), w = min(p[i], u);
f[j] += -f[u] - g[w] + s2[min(K, a[w])];
}
}
for (int i = 1; i <= tot; i++) f[i]++;
ll ans = 0;
for (int i = 1; i <= tot; i++) {
ans += 1ll * (f[i] - f[i - 1]) * (n / a[i]) * F(m / a[i]);
}
cout << ans << '\n';
}
详细
Pretests
Final Tests
Test #1:
score: 4
Accepted
time: 1ms
memory: 5784kb
input:
9 19 2
output:
78
result:
ok 1 number(s): "78"
Test #2:
score: 4
Accepted
time: 1ms
memory: 7752kb
input:
97 9998 2
output:
395230
result:
ok 1 number(s): "395230"
Test #3:
score: 4
Accepted
time: 1ms
memory: 7780kb
input:
925 776383828 2
output:
291158369963
result:
ok 1 number(s): "291158369963"
Test #4:
score: 4
Accepted
time: 1ms
memory: 5708kb
input:
8901 326326877 2
output:
1177246855340
result:
ok 1 number(s): "1177246855340"
Test #5:
score: 4
Accepted
time: 1ms
memory: 5568kb
input:
10 18 3
output:
85
result:
ok 1 number(s): "85"
Test #6:
score: 4
Accepted
time: 1ms
memory: 5716kb
input:
99 9124 3
output:
414445
result:
ok 1 number(s): "414445"
Test #7:
score: 4
Accepted
time: 1ms
memory: 7768kb
input:
876 435006787 3
output:
173773888677
result:
ok 1 number(s): "173773888677"
Test #8:
score: 4
Accepted
time: 1ms
memory: 5676kb
input:
9077 999901423 3
output:
4138517057280
result:
ok 1 number(s): "4138517057280"
Test #9:
score: 4
Accepted
time: 1ms
memory: 5692kb
input:
8 18 70
output:
44
result:
ok 1 number(s): "44"
Test #10:
score: 4
Accepted
time: 1ms
memory: 5788kb
input:
99 7689 100
output:
257777
result:
ok 1 number(s): "257777"
Test #11:
score: 4
Accepted
time: 1ms
memory: 5716kb
input:
904 791040170 780
output:
168263165839
result:
ok 1 number(s): "168263165839"
Test #12:
score: 4
Accepted
time: 0ms
memory: 5728kb
input:
9752 700341570 1900
output:
2191452433400
result:
ok 1 number(s): "2191452433400"
Test #13:
score: 4
Accepted
time: 2ms
memory: 5744kb
input:
67890 96085338 98
output:
2313308017745
result:
ok 1 number(s): "2313308017745"
Test #14:
score: 4
Accepted
time: 8ms
memory: 6016kb
input:
199752 831377991 582
output:
49964059187765
result:
ok 1 number(s): "49964059187765"
Test #15:
score: 4
Accepted
time: 4ms
memory: 5792kb
input:
402829 239198013 1974
output:
25093728301882
result:
ok 1 number(s): "25093728301882"
Test #16:
score: 4
Accepted
time: 3ms
memory: 5916kb
input:
920812 97518123 30
output:
22745569858620
result:
ok 1 number(s): "22745569858620"
Test #17:
score: 4
Accepted
time: 11ms
memory: 6304kb
input:
2000000 902323111 630
output:
399982029285532
result:
ok 1 number(s): "399982029285532"
Test #18:
score: 4
Accepted
time: 11ms
memory: 7644kb
input:
5000000 1000000000 1122
output:
1315768281328847
result:
ok 1 number(s): "1315768281328847"
Test #19:
score: 4
Accepted
time: 0ms
memory: 6028kb
input:
10000000 100000000 100
output:
337737297053529
result:
ok 1 number(s): "337737297053529"
Test #20:
score: 4
Accepted
time: 12ms
memory: 6536kb
input:
19283746 992837465 330
output:
4445506723817465
result:
ok 1 number(s): "4445506723817465"
Test #21:
score: 4
Accepted
time: 9ms
memory: 6072kb
input:
20000000 1000000000 1540
output:
5417869022476158
result:
ok 1 number(s): "5417869022476158"
Test #22:
score: 4
Accepted
time: 4ms
memory: 5692kb
input:
79331983 76782798 210
output:
1350083306292618
result:
ok 1 number(s): "1350083306292618"
Test #23:
score: 4
Accepted
time: 4ms
memory: 6040kb
input:
99997327 86263723 1999
output:
5241443368179591
result:
ok 1 number(s): "5241443368179591"
Test #24:
score: 4
Accepted
time: 18ms
memory: 6676kb
input:
967272686 923726686 1260
output:
198034442762888587
result:
ok 1 number(s): "198034442762888587"
Test #25:
score: 4
Accepted
time: 18ms
memory: 6804kb
input:
999193233 997313141 1848
output:
242952866318443894
result:
ok 1 number(s): "242952866318443894"
Extra Test:
score: 0
Extra Test Passed