Cod sursa(job #354978)
Utilizator | Osan Andreea Maria deeyame | Data | 9 octombrie 2009 22:39:36 |
---|---|---|---|
Problema | Algoritmul lui Euclid | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include<fstream>
using namespace std;
ifstream fin("euclid2.in");
ofstream fout("euclid2.out");
int Cmmdc( int x, int y);
int main()
{
int t, a, b;
fin >> t;
for( int i = 0; i < t; ++i )
{
fin >> a >> b;
fout << Cmmdc( a, b ) << ' ';
}
fin.close();
fout.close();
return 0;
}
int Cmmdc(int x, int y)
{
fin >> x >> y;
if( y == 0 ) return x;
int rest;
do
{
rest = x % y;
x = y;
y = rest;
}while(rest);
return x;
}