Cod sursa(job #1355273)
Utilizator | Data | 22 februarie 2015 15:58:41 | |
---|---|---|---|
Problema | Algoritmul lui Euclid | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.44 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
std::ifstream f("euclid2.in");
std::ofstream g("euclid2.out");
int n;
long int x,y;
f>>n;
while (n-->=0) {
f>>x>>y;
if (y>x) {
y+=x;x=y-x;y=y-x;
}
while (y%x!=0) {
y=y%x;y+=x;x=y-x;y=y-x;
}
g<<x<<endl;
}
f.close();
g.close();
return 0;
}