Pagini recente » Cod sursa (job #1483602) | Cod sursa (job #1166110) | Cod sursa (job #1113063) | Cod sursa (job #2448934) | Cod sursa (job #604636)
Cod sursa(job #604636)
#include <stdio.h>
#include <math.h>
int n;
int totient[1000005];
void precalc()
{
for (int i = 1; i <= n ; ++i)
totient[i] = i;
for (int i = 2; i <= n; ++i)
{
if (totient[i] == i)
{
for (int j = 2*i ; j <=n ; j+=i)
totient[j] -= totient[j]/i;
totient[i]--;
}
}
}
int main()
{
freopen("fractii.in","r",stdin);
freopen("fractii.out","w",stdout);
scanf("%d",&n);
precalc();
long long int rez = 1;
for (int i = 2 ; i <= n ; ++i)
{
rez += 2*totient[i];
}
printf("%lld\n",rez);
return 0;
}