Cod sursa(job #3214091)

Utilizator aeftenieAlexandru Daniel Eftenie aeftenie Data 13 martie 2024 19:36:29
Problema Algoritmul lui Euclid Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.45 kb
#include <bits/stdc++.h>

using namespace std;

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

int euclid(int a, int b) {
    if(a < b)
        swap(a, b);
    while(b) {
        int c = a % b;
        a = b;
        b = c;
    }
    return a;
}

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

    fin.close();
    fout.close();
    return 0;
}