Cod sursa(job #604632)
| Utilizator | Data | 23 iulie 2011 19:30:29 | |
|---|---|---|---|
| Problema | Fractii | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.48 kb |
#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;
}