Pagini recente » Cod sursa (job #581743) | Cod sursa (job #289630) | Cod sursa (job #1401853) | Cod sursa (job #768096) | Cod sursa (job #604634)
Cod sursa(job #604634)
#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();
int rez = 1;
for (int i = 2 ; i <= n ; ++i)
{
rez += 2*totient[i];
}
printf("%d\n",rez);
return 0;
}