Cod sursa(job #2497489)
| Utilizator | Data | 22 noiembrie 2019 19:21:12 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid | Scor | 40 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.41 kb |
#include <iostream>
#include <algorithm>
int tests, a, b;
int cmmdc(int a, int b) {
if (a < b) {
std::swap(a, b);
}
while (b) {
a = a % b;
std::swap(a, b);
}
return a;
}
int main() {
freopen("euclid2.in", "r", stdin);
freopen("euclid2.out", "w", stdout);
std::cin >> tests;
for (int test_no = 0; test_no < tests; test_no++) {
std::cin >> a >> b;
std::cout << cmmdc(a, b) << "\n";
}
return 0;
}