Pagini recente » Cod sursa (job #3269933) | Cod sursa (job #2122605) | Cod sursa (job #869859) | Cod sursa (job #2417728) | Cod sursa (job #1474135)
#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();
int s = 0;
for (int i = 2; i <= n; ++i) {
s += totient[i];
}
s = 2 * s + 1;
printf("%d", s);
return 0;
}