Pagini recente » Cod sursa (job #3241139) | Cod sursa (job #357454) | Cod sursa (job #1397432) | Cod sursa (job #1654308) | Cod sursa (job #123449)
Cod sursa(job #123449)
#include<stdio.h>
#include<math.h>
int main()
{
long n,i,j,p,x,k,f=0;
unsigned long e;
int v;
freopen("fractii.in", "r", stdin);
freopen("fractii.out", "w", stdout);
scanf("%ld", &n);
for(i=2; i<=n; i++)
{
x=i;
p=0;
v=0;
while(x%2==0)
{
p++;
x=x/2;
v=1;
}
if(p>0)
e=(long unsigned int)pow(2,p-1);
else
e=1;
for(j=3; (x!=1)&&(j<=sqrt(i)); j+=2)
{
if(x%j==0)
{
v=1;
p=0;
while(x%j==0)
{
p++;
x=x/j;
}
e=e*(j-1)*(long unsigned int)pow(j,p-1);
}
}
if(v==0)
e=i-1;
else
{
for(k=j+2; x!=1; k+=2)
{
if(x%k==0)
{
p=0;
while(x%k==0)
{
p++;
x=x/k;
}
e=e*(k-1)*(long unsigned int)pow(k,p-1);
}
}
}
f=f+2*e;
}
f=f+1;
printf("%ld\n", f);
return 0;
}