Cod sursa(job #1046817)

Utilizator gabrielinelusGabriel-Robert Inelus gabrielinelus Data 3 decembrie 2013 16:36:11
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.7 kb
#include <cstdio>

using namespace std;

void euclid(long long a,long long b,long long  &d,long long &x,long long &y)
{
    if(!b)
    {
        x = 1;
        y = 0;
        d = a;
        return;
    }
    long long x1,y1;
    euclid(b,a%b,d,x1,y1);
    x = y1;
    y = x1-(a/b)*y1;
}

int main()
{

    freopen("euclid3.in","r",stdin);
    freopen("euclid3.out","w",stdout);

    long long a,b,c,d,x,y;
    int N;
    scanf("%d",&N);
    for(int line = 1; line <= N; ++line){
        scanf("%lld%lld%lld",&a,&b,&c);
        euclid(a,b,d,x,y);
        if(c%d != 0)
            printf("0 0\n");
        else
            printf("%lld %lld\n",x*c/d,y*c/d);
    }

    return 0;
}