Cod sursa(job #2225152)
Utilizator | Data | 26 iulie 2018 10:22:14 | |
---|---|---|---|
Problema | Algoritmul lui Euclid | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
#include <iostream>
using namespace std;
int divz(int x, int y) {
int a = x;
if (y < x) {
a = y;
}
while (a > 1) {
if (x % a == 0 && y % a == 0)
return a;
else
a--;
}
return a;
}
int main(int argc, char const *argv[])
{
ifstream inFile;
inFile.open("euclid2.in");
ofstream outf("euclid2.out");
int nums, x, y;
inFile >> nums;
for (int i = 0; i < nums; ++i) {
inFile >> x >> y;
outf << divz(x, y) << "\n";
}
outf.close();
inFile.close();
return 0;
}