Cod sursa(job #920443)

Utilizator rudarelLup Ionut rudarel Data 20 martie 2013 13:58:13
Problema Algoritmul lui Euclid Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.54 kb
#include <stdio.h>

typedef long long int li;

li cmmdc(li a, li b)
{
    li t;
    if (a % b == 0) return b;
    while(a > b)
    {
            t = a;
            a = a / b;
            b = t % b;           
    }
    return b;
}

int main()
{
    li a, b;
    int t;
    freopen("cmmdc.in","r",stdin);
    freopen("cmmdc.out","w",stdout);
    scanf("%d",&t);
    while(t) {
     scanf("%lld %lld",&a,&b);
     if (a > b) printf("%lld\n",cmmdc(a,b));
     else printf("%lld\n",cmmdc(b,a));
     t--;
    }
    return 0;
}