Cod sursa(job #486766)

Utilizator AndrewTheGreatAndrei Alexandrescu AndrewTheGreat Data 22 septembrie 2010 19:02:23
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <iostream>
#include <stdio.h>
#define L long long
using namespace std;

void euclid(L a, L b, L *d, L *x, L *y)
{
    if(b == 0)
    {
        *y = 0;
        *x = 1;
        *d = a;
    }
    else
    {
        L x0, y0;
        euclid(b, a%b, d, &x0, &y0);
        *x = y0;
        *y = x0 - (a / b) * y0;
    }
}

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

    int N;
    scanf("%d",&N);

    long long a,b,c,d,x,y;
    while(N--)
    {
        scanf("%I64d %I64d %I64d",&a,&b,&c);
        euclid(a,b,&d,&x,&y);
        if( c % d)
            printf("0 0\n");
        else
            printf("%I64d %I64d\n",x * (c / d),y * (c / d));
    }
    return 0;
}