Cod sursa(job #2360280)

Utilizator AplayLazar Laurentiu Aplay Data 1 martie 2019 17:11:27
Problema Algoritmul lui Euclid Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 kb
#include <stdio.h>
#include <iostream>

using namespace std;

int T;
long long x, y;

long long gcd(long long a, long long b) {
    long long r = a % b;
    while (true) {
        a = b;
        b = r;
        if (0 == b) {
            return a;
        }
        r = a % b;
    }

    return a;
}

int main() {
    freopen("euclid2.in", "r", stdin);
    freopen("euclid2.out", "w", stdout);

    cin >> T;
    while (T--) {
        cin >> x >> y;
        cout << (x < y ? gcd(x, y) : gcd(y, x)) << endl;
    }

    return 0;
}