Cod sursa(job #16625)

Utilizator maria_bobesMaria Bobes maria_bobes Data 13 februarie 2007 19:44:22
Problema Fractii Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include<stdio.h>
FILE *f;
long n;
int main()
{
 long s=1;
 f=fopen("fractii.in","r");
 fscanf(f,"%d",&n);
 fclose(f);
 for (int i=2;i<=n;i++)
 {
   long x,d;
   float p=1;
   x=i;
   if(x%2==0)
    p=0.5;
   while(x%2==0)
    x=x/2;
   for(d=3;d<=x;d++)
   {
   if(x%d==0)
    p=p-p/d;
   while(x%d==0)
    x=x/d;
   d++;
   }
  s+=2*i*p;
 }
 f=fopen("fractii.out","w");
 fprintf(f,"%d",s);
 return 0;
}