Cod sursa(job #735286)

Utilizator visanrVisan Radu visanr Data 15 aprilie 2012 23:33:24
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;


long gcd(long a,long b,long &x,long &y)
{
     if(b==0)
     {
             x=1;
             y=0;
             return a;
     }
     long xaux,yaux,d;
     d=gcd(b,a%b,xaux,yaux);
     x=yaux;
     y=xaux-(a/b)*yaux;
     return d;
}


int main()
{
    freopen("euclid3.in","r",stdin);
    freopen("euclid3.out","w",stdout);
    long a,b,c,t;
    scanf("%ld", &t);
    for(;t>-1;t--)
    {
                  scanf("%ld %ld %ld", &a,&b,&c);
                  long d,x,y;
                  d=gcd(a,b,x,y);
                  if(c%d) printf("0 0\n");
                  else printf("%ld %ld\n", x*(c/d),y*(c/d));
    }
    return 0;
}