Pagini recente » Cod sursa (job #2584127) | Cod sursa (job #89464) | Cod sursa (job #2915293) | Cod sursa (job #790306) | Cod sursa (job #396000)
Cod sursa(job #396000)
#include<stdio.h>
using namespace std;
#define dim 1000001
#include<math.h>
#include<string.h>
int n,p[dim],i,j,nr,N,P;
long long nrf;
void descompune()
{j=1; nr=0;
while(N>1)
{j++;
while(N%j==0)
{N/=j;
if(p[j]==0)
nr++;
p[j]++; }
}
}
int main ()
{
FILE *f=fopen("fractii.in","r"), *g=fopen("fractii.out","w");
fscanf(f,"%d",&n);
for(i=2;i<=n;i++)
{N=i;P=1;
descompune();
for(j=2;j<=i;j++)
{ if(p[j]!=0)
{
P*=(j-1)*(long long)pow(j,p[j]-1);
nr--;
}
if(nr==0)
break;
}
nrf+=P;
memset(p,0,sizeof(p));
}
fprintf(g,"%lld",2*nrf+1);
fclose(f);
fclose(g);
return 0;
}