Cod sursa(job #110533)

Utilizator eddieOlariu Eduard Iuliu eddie Data 26 noiembrie 2007 21:55:34
Problema Fractii Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <stdio.h>
unsigned long long nrprimecuxmaimicicax ( long x )
 {
  long d=7;
  unsigned long long h=1;
  long dx=x;
  if ( x % 2 ==0 )
    {
     dx/=2;
     x/=2;
    }
  while ( x % 2 ==0 && x != 0 && x != 1 )
   {
    x/=2;
   }
  if ( x % 3 ==0 )
    {
     h*=2;
     dx/=3;
     x/=3;
    }
  while ( x % 3 ==0 && x != 0 && x != 1 )
   {
    x/=3;
   }
  if ( x % 5 ==0 )
    {
     h*=4;
     dx/=5;
     x/=5;
    }
  while ( x % 5 ==0 && x != 0 && x != 1 )
   {
    x/=5;
   }
  while ( x != 1 && x != 0 && d <= x )
   {
    if ( x % d == 0 )
       {
	dx/=d;
	x/=d;
	h=h*(d-1);
       }

    while  ( x % d == 0 && x != 0 && x != 1 )
       x/=d;
    d+=2;
   }
  return dx*h;
 }
int main()
 {
  freopen("fractii.in","r",stdin);
  freopen("fractii.out","w",stdout);
  long n;
  scanf("%ld",&n);
  long i;
  unsigned long long hhj=0;
  for (i=2;i<=n;i++)
      {
       hhj+=nrprimecuxmaimicicax(i);
      }
  printf("%ulld",hhj*2+1);
  fclose(stdout);
  return 0;
 }