Pagini recente » Cod sursa (job #2624851) | Cod sursa (job #2230436) | Cod sursa (job #1328448) | Cod sursa (job #1470398) | Cod sursa (job #92337)
Cod sursa(job #92337)
#include <stdio.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<n+1;i+=2)
totient[i]=totient[i]-totient[i]/2;
totient[2]=1;
for (int i=3;i<n+1;i+=2)
{
if (totient[i]==i)
{
for(int j=2*i;j<n+1;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()
{
citire();
for (int i=0;i<n+1;i++)
totient[i]=i;
for (int i=0;i<n+1;i++)
totient[i]=i;
sum = 1;
ciur();
for (int i=2;i<=n;i++)
sum += 2*totient[i];
scrie();
return 0;
}