Pagini recente » Cod sursa (job #51932) | Cod sursa (job #1562182) | Cod sursa (job #2273316) | Cod sursa (job #3225443) | Cod sursa (job #2500225)
#include <cstdio>
#include <bitset>
using namespace std;
const int NMAX = 1000505;
bitset<NMAX> notPrime;
int phi[NMAX], N;
void precomputeTotientFunction() {
for (int i = 2; i < NMAX; i++) {
phi[i] = i;
}
for (int i = 2; i < NMAX; i++) {
if (!notPrime[i]) {
for (int j = i; j < NMAX; j += i) {
phi[j] = phi[j] / i * (i - 1);
notPrime[j] = 1;
}
}
}
}
int main() {
freopen("fractii.in", "r", stdin);
freopen("fractii.out", "w", stdout);
precomputeTotientFunction();
scanf("%d", &N);
long long result = 0;
for (int i = 2; i <= N; i++) {
result += phi[i] * 2;
}
// add 1 / 1 once only
printf("%lld\n", result + 1);
return 0;
}