QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#383258 | #3295. 循环之美 | Ecec243 | 100 ✓ | 313ms | 122240kb | C++23 | 1.7kb | 2024-04-09 07:55:24 | 2024-04-09 07:55:25 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <map>
#include <cstring>
using namespace std;
typedef long long LL;
const int S = 1e7 + 1, T = 2005, INF = 0x3f3f3f3f;
int primes[S], tot, fac[S], mu[S];
bool st[S];
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
map<int, int> F[T], G[T], mu2;
LL ans;
LL f(int n, int k) {
if (n == 0) return 0;
if (n == 1) return 1;
if (F[k].count(n)) return F[k][n];
else if (k > 1) {
int p = fac[k];
return F[k][n] = (f(n, k / p) + f(n / p, k));
} else {
if (n < S) return mu[n];
int res = 1;
for (int l = 2, r, t; l <= n; l = r + 1) {
t = n / l, r = n / t;
res -= f(t, k) * (r - l + 1);
}
return F[k][n] = res;
}
}
LL g(int n, int k) {
if (n == 0) return 0;
if (G[k].count(n)) return G[k][n];
else if (k > 1) {
int p = fac[k];
return G[k][n] = (g(n, k / p) - g(n / p, k / p));
} else return n;
}
void init() {
for (int i = 1; i < S; i++) mu[i] = 1;
for (int i = 2; i < S; i++) {
if (!st[i]) primes[++tot] = i, mu[i] = -1, fac[i] = i;
for (int j = 1; primes[j] * i < S; j++) {
st[primes[j] * i] = true;
fac[primes[j] * i] = primes[j];
if (i % primes[j] == 0) {
mu[i * primes[j]] = 0;
break;
}
mu[i * primes[j]] = -mu[i];
}
}
for (int i = 2; i < S; i++) mu[i] += mu[i - 1];
}
int main() {
init();
int n, m, K; scanf("%d%d%d", &n, &m, &K);
for (int i = 2; i <= K; i++) {
while (K % i == 0 && (K / i) % i == 0) K /= i;
}
for (int l = 1, r, a, b; l <= min(n, m); l = r + 1) {
a = n / l, b = m / l, r = min(min(n, m), min(n / a, m / b));
ans += a * (f(r, K) - f(l - 1, K)) * g(b, K);
}
printf("%lld\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 4
Accepted
time: 102ms
memory: 94628kb
input:
9 19 2
output:
78
result:
ok 1 number(s): "78"
Test #2:
score: 4
Accepted
time: 108ms
memory: 94608kb
input:
97 9998 2
output:
395230
result:
ok 1 number(s): "395230"
Test #3:
score: 4
Accepted
time: 93ms
memory: 94672kb
input:
925 776383828 2
output:
291158369963
result:
ok 1 number(s): "291158369963"
Test #4:
score: 4
Accepted
time: 99ms
memory: 95352kb
input:
8901 326326877 2
output:
1177246855340
result:
ok 1 number(s): "1177246855340"
Test #5:
score: 4
Accepted
time: 96ms
memory: 94580kb
input:
10 18 3
output:
85
result:
ok 1 number(s): "85"
Test #6:
score: 4
Accepted
time: 93ms
memory: 94640kb
input:
99 9124 3
output:
414445
result:
ok 1 number(s): "414445"
Test #7:
score: 4
Accepted
time: 97ms
memory: 94584kb
input:
876 435006787 3
output:
173773888677
result:
ok 1 number(s): "173773888677"
Test #8:
score: 4
Accepted
time: 100ms
memory: 95480kb
input:
9077 999901423 3
output:
4138517057280
result:
ok 1 number(s): "4138517057280"
Test #9:
score: 4
Accepted
time: 106ms
memory: 94460kb
input:
8 18 70
output:
44
result:
ok 1 number(s): "44"
Test #10:
score: 4
Accepted
time: 97ms
memory: 94644kb
input:
99 7689 100
output:
257777
result:
ok 1 number(s): "257777"
Test #11:
score: 4
Accepted
time: 99ms
memory: 95204kb
input:
904 791040170 780
output:
168263165839
result:
ok 1 number(s): "168263165839"
Test #12:
score: 4
Accepted
time: 117ms
memory: 98324kb
input:
9752 700341570 1900
output:
2191452433400
result:
ok 1 number(s): "2191452433400"
Test #13:
score: 4
Accepted
time: 100ms
memory: 98024kb
input:
67890 96085338 98
output:
2313308017745
result:
ok 1 number(s): "2313308017745"
Test #14:
score: 4
Accepted
time: 189ms
memory: 109868kb
input:
199752 831377991 582
output:
49964059187765
result:
ok 1 number(s): "49964059187765"
Test #15:
score: 4
Accepted
time: 161ms
memory: 106012kb
input:
402829 239198013 1974
output:
25093728301882
result:
ok 1 number(s): "25093728301882"
Test #16:
score: 4
Accepted
time: 129ms
memory: 100172kb
input:
920812 97518123 30
output:
22745569858620
result:
ok 1 number(s): "22745569858620"
Test #17:
score: 4
Accepted
time: 239ms
memory: 116936kb
input:
2000000 902323111 630
output:
399982029285532
result:
ok 1 number(s): "399982029285532"
Test #18:
score: 4
Accepted
time: 241ms
memory: 118188kb
input:
5000000 1000000000 1122
output:
1315768281328847
result:
ok 1 number(s): "1315768281328847"
Test #19:
score: 4
Accepted
time: 115ms
memory: 98380kb
input:
10000000 100000000 100
output:
337737297053529
result:
ok 1 number(s): "337737297053529"
Test #20:
score: 4
Accepted
time: 252ms
memory: 118320kb
input:
19283746 992837465 330
output:
4445506723817465
result:
ok 1 number(s): "4445506723817465"
Test #21:
score: 4
Accepted
time: 244ms
memory: 118332kb
input:
20000000 1000000000 1540
output:
5417869022476158
result:
ok 1 number(s): "5417869022476158"
Test #22:
score: 4
Accepted
time: 132ms
memory: 102264kb
input:
79331983 76782798 210
output:
1350083306292618
result:
ok 1 number(s): "1350083306292618"
Test #23:
score: 4
Accepted
time: 112ms
memory: 96708kb
input:
99997327 86263723 1999
output:
5241443368179591
result:
ok 1 number(s): "5241443368179591"
Test #24:
score: 4
Accepted
time: 298ms
memory: 121208kb
input:
967272686 923726686 1260
output:
198034442762888587
result:
ok 1 number(s): "198034442762888587"
Test #25:
score: 4
Accepted
time: 313ms
memory: 122240kb
input:
999193233 997313141 1848
output:
242952866318443894
result:
ok 1 number(s): "242952866318443894"
Extra Test:
score: 0
Extra Test Passed