-
Notifications
You must be signed in to change notification settings - Fork 1
/
uva_10738.cpp
63 lines (54 loc) · 1.1 KB
/
uva_10738.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
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i = a, _b = b; i < _b; ++i)
#define FOR(i, a, b) for(int i = a, _b = b; i <= b; ++i)
#define FORD(i, a, b) for(int i = a, _b = b; i >= b; --i)
using namespace std;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef long long llong;
const int MX = 1E6+1;
bool isSF[MX], isPrime[MX];
int cnt[MX], M[MX], mu[MX];
void sieve () {
memset(isSF, true, sizeof isSF);
memset(isPrime, true, sizeof isPrime);
REP(i, 2, MX) {
if(isPrime[i]) {
for(int j = i; j < MX; j += i) {
isPrime[j] = false;
cnt[j]++;
}
llong sqr = (llong)i*i;
if(sqr > MX) continue;
for(int j = sqr; j < MX; j += sqr) {
isSF[j] = false;
}
}
}
}
void calc () {
sieve();
mu[1] = 1;
M[1] = 1;
REP(i, 2, MX) {
if(isSF[i]) {
mu[i] = (cnt[i]%2 == 0) ? 1 : -1;
}
else{
mu[i] = 0;
}
M[i] = M[i-1] + mu[i];
}
}
int main() {
#ifndef Home
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
calc();
int n;
while(scanf("%d", &n) and n) {
printf("%8d%8d%8d\n", n, mu[n], M[n]);
}
return 0;
}