Cod sursa(job #2714407)

Utilizator iuliangal186Gal Iulian iuliangal186 Data 1 martie 2021 19:42:31
Problema Algoritmul lui Euclid Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.55 kb
#include <iostream>
#include <fstream>
using namespace std;

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

int main()
{
    long long n, x, y, r;
    fin >> n;
    while(n != 0)
    {
        fin >> x >> y;
        if (x == 0 || y == 0)
                fout << 1;
        else
        {
            r = x % y;
            while(r > 0 || r < 0)
            {
                x = y;
                y = r;
                r = x % y;
            }
            fout << y << endl;
        }

        n--;
    }
    return 0;
}