Cod sursa(job #443859)

Utilizator wamfeverDobos Ionut wamfever Data 18 aprilie 2010 17:50:28
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include<fstream>
using namespace std;
ifstream fin("fractii.in");
ofstream fout("fractii.out");

int n, i, j;
long long nr;

int cmmdc(int a, int b)
{int c;
               while(b)
               {
                       c=a%b;
                       a=b;
                       b=c;
                       }
return a;
}

int main()
{
    fin >> n;
    nr=n;
    for(i=2;i<=n;i++)
    //{                
                       for(j=1;j<=n;j++)
                     //{
                                     //fout << "cmmdc(" << i << "," << j << ")=" << cmmdc(i,j)<<"\n";
                                      if(cmmdc(i,j)==1)nr++;
                        //}
    //fout << "\n";
    //}
    fout << nr;
    fin.close();
    fout.close();
    return 0;
}