Cod sursa(job #206758)
| Utilizator | Data | 9 septembrie 2008 12:37:53 | |
|---|---|---|---|
| Problema | Algoritmul lui Euclid | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.39 kb |
#include<iostream.h>
#include<fstream.h>
unsigned long i,j,a,b,x;
int main ()
{
ifstream f("euclid2.in");
ofstream g("euclid2.out");
f>>x;
for (i=0;i<x;i++)
{f>>a>>b;
if (a==b) g<<a<<'\n';
else {if (a>b) {for (j=b;j>=0;j--)
if (a%j==0 && b%j==0) {g<<j<<'\n';break;}}
if (a<b) {for (j=a;j>=0;j--)
if (a%j==0 && b%j==0) {g<<j<<'\n';break;}}
}
}
return 0;
}
