Pagini recente » Istoria paginii runda/hlo_cj_av_trie | Cod sursa (job #963244) | Cod sursa (job #874938) | Cod sursa (job #871818) | Cod sursa (job #112812)
Cod sursa(job #112812)
#include <stdio.h>
#include <malloc.h>
unsigned long n;
int* totient;
unsigned long calcul(int n)
{
int i,j,s=0;
for(i=2; i<=n/2; i++)
{
if (i==2) totient[i]=1;
if (totient[i]==1)
{
for (j=i+1; j<=n; j++)
{
if (i==2) totient[j]=1;
if (j%i==0)
{
if (totient[j]>1) totient[j]=totient[j]*(i-1)/i;
else totient[j]=j*(i-1)/i;
}
}
}
if (totient[i]==1) totient[i]=i-1;
s+=totient[i];
}
for (i=n; i>n/2; i--)
{
if (totient[i]==1) totient[i]=i-1;
s+=totient[i];
}
return s;
}
int main()
{
FILE *f, *g;
f=fopen("fractii.in","r");
fscanf(f,"%lu",&n);
totient=(int*) malloc ((n+1)*sizeof(int));
g=fopen("fractii.out","w");
fprintf(g,"%lu",2*calcul(n)+1);
return 0;
}