Cod sursa(job #1125555)

Utilizator alexmarMarinescu Alexandru alexmar Data 26 februarie 2014 18:22:37
Problema Algoritmul lui Euclid Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include<iostream>
#include<fstream>
using namespace std;

ifstream fin("euclid2.in");
ofstream fout("euclid2.out");


long cmmdc(long x, long y){
if(x>=y){
    if(x%y==0)return y;
    else {x=x%y;cmmdc(y,x);}
}else if(y%x==0)return x;
    else{y=y%x;cmmdc(x,y);}

}

int main()
{
    long a,x,y;
    fin>>a;
    while(a){
        fin>>x>>y;
        fout<<cmmdc(x,y)<<"\n";a--;
    }

    return 0;
}