Pagini recente » Cod sursa (job #123812) | Infoarena Monthly 2012 - Runda 7 - Solutii | Istoria paginii runda/simulare-oji-matei-2 | Cod sursa (job #1867658) | Cod sursa (job #2788124)
#include <stdio.h>
#include <stdbool.h>
int e[1000005] = {};
int main() {
freopen("fractii.in", "r", stdin);
freopen("fractii.out", "w", stdout);
int n, i, j;
unsigned long long ans = 1;
bool p[1000005] = {};
scanf("%d", &n);
for(i = 1; i <= n; ++i)
e[i] = i;
for(i = 2; i <= n; ++i)
if(p[i] == 0) {
for(j = i; j <= n; j += i) {
p[j] = 1;
e[j] = e[j] / i * (i-1);
}
}
for(i = 2; i <= n; ++i)
ans += 2*e[i];
printf("%lld\n", ans);
}