Cod sursa(job #352023)

Utilizator manu.budauBudau Emanuel manu.budau Data 30 septembrie 2009 09:03:44
Problema Fractii Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream.h>
ifstream f("fractii.in");
ofstream g("fractii.out");

int x[1000000], a,i,j,n,k,p;

long fi(long n)
 { long d=2;
   long P=n;
     while(n>1) { if(n%d==0) { P=P*(d-1)/d;
                               while(n%d==0)n/=d;
                             } 
                  else d++;
                } 
   return P;
 }
 
int main()
{ x[0]=2;
  x[1]=3;
  x[2]=5;
  p=2;
    f>>n;
    for(k=7;k<=n;k+=2)
       {  for(i=1;i<=p&&k%x[i];i++);
          if(i>p) x[++p]=k;
       } 
       
   
   a=1;
   j=0;
   for(i=1;i<n;i++) { if(i+1==x[j]){ j++;
                                  a+=2*i;
                                }
                      else a+=2*fi(i+1);
   
                     }
                      
   g<<a<<"\n";                   
   f.close();
   g.close();
   return 0;
}