Pagini recente » Cod sursa (job #360989) | Cod sursa (job #1309016) | Cod sursa (job #2395959) | Cod sursa (job #2744347) | Cod sursa (job #92322)
Cod sursa(job #92322)
#include <stdio.h>
#include <string.h>
using namespace std;
long long totient[1000000];
int n;
long long sum;
void citire()
{
freopen("fractii.in","r",stdin);
scanf("%d",&n);
}
void ciur()
{
for (int i=4;i<1000000;i+=2)
totient[i]=totient[i]-totient[i]/2;
for (int i=3;i<1000000;i+=2)
{
if (totient[i]==0)
{
for(int j=2*i;j<1000000;j+=i)
totient[j]=totient[j]-totient[j]/i;
totient[i]=i-1;
}
}
}
void scrie()
{
freopen("fractii.out","w",stdout);
printf("%lld",sum);
fclose(stdout);
}
int main()
{
for (int i=0;i<1000000;i++)
totient[i]=i;
citire();
sum = 1;
ciur();
for (int i=2;i<=n;i++)
sum += 2*totient[i];
scrie();
//printf("%d",totient(4));
return 0;
}