Cod sursa(job #883316)

Utilizator teodor98Teodor Sz teodor98 Data 19 februarie 2013 21:57:11
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <iostream>
#include <fstream>
using namespace std;
int cmmdc (int a,int b)
{
 while (a!=b)
  if (a>b)
   a=a-b;
  else
   b=b-a;

 return a;
}
int main()
{
    long a, c, j, i;
    fstream f;
    f.open("fractii.in", fstream::in);
    f >>a;
    c = 0;
    for(i = 1;i<=a;i++)
    {

        for(j = 1;j<=a;j++)
        {

            if(cmmdc(i,j) == 1)
            {

                c++;
            }

        }
    }
    f.close();
    f.open("fractii.out", fstream::out);
    f << c;


    return 0;
}