Cod sursa(job #2640401)

Utilizator Stefan4814Voicila Stefan Stefan4814 Data 6 august 2020 13:03:38
Problema Algoritmul lui Euclid Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.45 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;

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

int gcd(int a, int b) {
    if(b < a)
        swap(b, a);

    while(a != 0) {
        int rest = b % a;
        b = a;
        a = rest;
    }
    return b;
}

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

    return 0;
}