Cod sursa(job #3311572)

Utilizator raul41917raul rotar raul41917 Data 23 septembrie 2025 12:25:02
Problema Algoritmul lui Euclid Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.51 kb
#include <iostream>
#include <fstream>
using namespace std;

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

int main(){

    int tests;
    fin >> tests;

    for(int test = 0; test < tests; test++){
        int a, b;
        fin >> a >> b;

        if(a < b){
            int aux = a;
            a = b;
            b = aux;
        }

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

        fout << b << endl;
    }
    return 0;
}