Cod sursa(job #551071)

Utilizator sw_nullSabadac Petru-Gabriel sw_null Data 10 martie 2011 12:10:13
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb

#include<cstdio>

 int main ( )

  {
    int n, i, j;
    long long int s;
    FILE * f = fopen ( "fractii.in", "r" );

    fscanf ( f, "%d", &n ); fclose ( f );
    s = 2 * n - 1;

    for ( i = 2; i <= n; i++ )
     for ( j = 2; j <= n; j++ )
      {
        if ( i != j )
         { 
           int a = i, b = j, c;
           if ( b > a ) 
            {
              c = a; a = b; b = c;
            }
           while ( b != 0 )
            {
              c = b; b = a % b; a = c;
            }
          if ( a == 1 ) s++; 
         }
      }

   f = fopen ( "fractii.out", "w" );
   fprintf ( f, "%lld\n", s );
   fclose( f );

   return 0;

 }