Cod sursa(job #1049609)
| Utilizator | Data | 7 decembrie 2013 16:17:30 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.61 kb |
#include <iostream>
#include <fstream>
using namespace std;
int euclid(long x,long y)
{
long aux;
while(y)
{
aux=x%y;
x=y;
y=aux;
}
return x;
}
int main()
{
ifstream fin("euclid2.in");
ofstream fout("euclid2.out");
long x,y,aux;
fin>>x;
while(fin>>x>>y)
{
if(y<x)
{
aux=x;
x=y;
y=aux;
}
if(x==0)
fout<<y;
else
fout<<euclid(x,y);
fout<<"\n";
}
return 0;
}
