Cod sursa(job #2180231)
Utilizator | Data | 20 martie 2018 18:42:07 | |
---|---|---|---|
Problema | Fractii | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.44 kb |
#include <iostream>
#include <fstream>
using namespace std;
int cmmdc (int a, int b)
{
while (a!=b)
{
if (a>b) a-=b;
else b-=a;
}
return a;
}
int main()
{int nr=0,n,i,j;
ifstream f("fractii.in");
ofstream g("fractii.out");
f>>n;
for (i=1; i<=n; i++)
{
for (j=1; j<=n; j++)
if(cmmdc(i,j)==1) {nr++;}
}
g<<nr;
f.close();
g.close();
}