Cod sursa(job #26844)

Utilizator Boss_2007Marian Ciprian Boss_2007 Data 5 martie 2007 21:53:01
Problema Fractii Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include<stdio.h>
long int l,d,prim,x[1000],p,n,i,j,sol[200],e,nc;
long int prim1000()
{
	l=1;x[1]=2;d=3;
	for(i=3;i<=999;i=i+2)
	{ prim=1;
	  for(d=3;d*d<=i;d=d+2)
	  if(i%d==0) {prim=0;break;}
	  if(prim){l++;x[l]=i;}
	}
	return 0;
}
int main()
{
	FILE *f=fopen("fractii.in","r");
	fscanf(f,"%ld",&n);
	fclose(f);
	prim1000();
	sol[0]=1;
	for(j=2;j<=n;j++)
	{e=j;
	 nc=j;
	 for(i=1;i<=l;i++)
	 {if(x[i]*x[i]>nc)break;
	 if(nc%x[i]==0)
	 {e/=x[i];e*=x[i]-1;while(nc%x[i]==0)nc/=x[i];}
	 }
	if(nc>1) {e/=nc;e*=nc-1;}
	sol[0]=sol[0]+2*e;
	for(p=0;p<=sol[100];p++)
		{sol[p+1]+=sol[p]/10;
		 sol[p]%=10;}
	if(sol[sol[100]+1])sol[100]++;
	}
	f=fopen("fractii.out","w");
	for(i=sol[100];i>=0;i--)
	fprintf(f,"%ld",sol[i]);
	fprintf(f,"\n");
	fclose(f);
	return 0;
}