forked from marioyc/Online-Judge-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3435 - Ideal Puzzle Bobble.cpp
78 lines (57 loc) · 1.69 KB
/
3435 - Ideal Puzzle Bobble.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAXN 1000000
int mu[MAXN + 1],factor[MAXN + 1];
int sum_mu[MAXN + 1];
long long visible(int X, int Y){
long long ret = 0;
for(int s = 1,e;s <= X && s <= Y;s = e + 1){
int kx = X / s,ky = Y / s;
e = min(X / kx,Y / ky);
ret += (long long)(sum_mu[e] - sum_mu[s - 1]) * kx * ky;
}
return ret;
}
long long visible(int X, int Y, int Z){
long long ret = 0;
for(int s = 1,e;s <= X && s <= Y && s <= Z;s = e + 1){
int kx = X / s,ky = Y / s,kz = Z / s;
e = min(X / kx,min(Y / ky,Z / kz));
ret += (long long)(sum_mu[e] - sum_mu[s - 1]) * kx * ky * kz;
}
return ret;
}
int main(){
memset(factor,-1,sizeof factor);
mu[1] = 1;
sum_mu[1] = 1;
for(int i = 2;i <= MAXN;++i){
if(factor[i] == -1){
mu[i] = -1;
if(i <= MAXN / i)
for(int j = i*i;j <= MAXN;j += i)
factor[j] = i;
}else{
int cont = 0,aux = i,p = factor[i];
while(aux % p == 0 && cont < 2){
aux /= p;
++cont;
}
if(cont == 2) mu[i] = 0;
else mu[i] = -mu[i / p];
}
sum_mu[i] = sum_mu[i - 1] + mu[i];
}
int X,Y,Z;
while(scanf("%d %d %d",&X,&Y,&Z) == 3){
--X; --Y; --Z;
long long ans = visible(X,Y,Z) + visible(X,Y) + visible(Y,Z) + visible(Z,X);
if(X >= 1) ++ans;
if(Y >= 1) ++ans;
if(Z >= 1) ++ans;
printf("%lld\n",ans);
}
return 0;
}