Pagini recente » Cod sursa (job #937473) | Cod sursa (job #1709707) | Cod sursa (job #684041) | Cod sursa (job #261297) | Cod sursa (job #52368)
Cod sursa(job #52368)
#include<stdio.h>
long a[100],i,n,s,aux,j;
int main()
{
freopen("fractii.in","r",stdin);
freopen("fractii.out","w",stdout);
scanf("%ld",&n);
for(i=2;i<=n/2;++i)
if(!a[i])
for(j=2*i;j<=n;j+=i)
a[j]=1;
for(i=2;i<=n;++i)
{
if(!a[i])
{
s+=(i-1)*2;
continue;
}
else
{
aux=i;
if(i%2==0)
{
if(4<=i)
aux-=aux/2;
}
for(j=3;j<=i/2;j+=2)
if(i%j==0)
aux-=aux/j;
s+=2*aux;
continue;
}
}
printf("%ld",s+1);
return 0;
}