Pagini recente » Cod sursa (job #527482) | Cod sursa (job #2736366) | Cod sursa (job #2777720) | Cod sursa (job #2797468) | Cod sursa (job #3230525)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dumb(int n) {
ll sol = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (__gcd(i, j) == 1) {
sol++;
}
}
}
return sol;
}
int smart(int n) {
ll sol = 0;
vector<int> phi(n + 1);
for (int i = 1; i <= n; i++) {
phi[i] = i;
}
for (int i = 2; i <= n; i++) {
if (phi[i] == i) {
for (int j = i; j <= n; j += i) {
phi[j] /= i;
phi[j] *= (i - 1);
}
}
}
for (int i = 1; i <= n; i++) {
sol += phi[i];
}
return 2 * sol - 1;
}
int main() {
#ifdef INFOARENA
freopen ("flip.in", "r", stdin);
freopen ("flip.out", "w", stdout);
#endif
if (0) {
for (int i = 1; i <= 100; i++) {
assert(smart(i) == dumb(i));
}
}
int n;
while (cin >> n) {
cout << smart(n) << "\n";
}
return 0;
}