Cod sursa(job #2810417)

Utilizator robberttPopa Robert robbertt Data 29 noiembrie 2021 13:53:06
Problema Algoritmul lui Euclid Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <iostream>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n, a, b, c;
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> a >> b;
        if(a < b)
            swap(a, b);
        if(a % b == 0){
            cout << b << '\n';
            continue;
        }
        while(a != b){
            c = a;
            a = a % b;
            b = c;
        }
        cout << a << '\n';
    }
    return 0;
}