Pagini recente » Cod sursa (job #496508) | Cod sursa (job #232260) | Cod sursa (job #1559818) | Cod sursa (job #2029269) | Cod sursa (job #604632)
Cod sursa(job #604632)
#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()
{
int i = 0;
scanf("%d",&n);
precalc();
int rez = 1;
for (int i = 2 ; i <= n ; ++i)
{
rez += 2*totient[i];
}
printf("%d\n",rez);
return 0;
}