Cod sursa(job #798409)

Utilizator skyper96skyper skyper96 Data 16 octombrie 2012 16:34:04
Problema Algoritmul lui Euclid Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.69 kb
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
    ifstream f("euclid2.in");
    ofstream g("euclid2.out");
    unsigned short n,i,aux,j;
    unsigned long a,b;
    bool ok;
    f >> n;
    for (i=1;i<=n;i++)
    {
        f >> a >> b;
        if (a>b)
        {
            aux=a;
            a=b;
            b=aux;
        }
        ok=0;
        for(j=a;j>=2;j--)
        {
            if ((a%j==0)&&(b%j==0))
                {
                    ok=1;
                    break;
                }
        }
        if(ok==1)
            g << j << endl;
        if(ok==0)
            g << 1 << endl;
    }

f.close();
g.close();
return 0;
}