Pagini recente » Cod sursa (job #1326323) | Cod sursa (job #1395478) | Cod sursa (job #934972) | Cod sursa (job #3178283) | Cod sursa (job #1474136)
#include <stdio.h>
#include <string.h>
#define MAX 1000005
int n;
int totient[MAX];
void gentotient () {
for (int i = 2; i <= n; ++i) {
totient[i] = i-1;
}
for (int i = 2; i <= n; ++i) {
for (int j = 2 * i; j <= n; j+=i) {
totient[j] -= totient[i];
}
}
}
int main (void) {
freopen("fractii.in", "r", stdin);
freopen("fractii.out", "w", stdout);
scanf("%d", &n);
gentotient();
long long s = 0;
for (int i = 2; i <= n; ++i) {
s += (long long) totient[i];
}
s = 2 * s + 1;
printf("%Ld", s);
return 0;
}