Cod sursa(job #1753777)

Utilizator AlexandruRudiAlexandru Rudi AlexandruRudi Data 7 septembrie 2016 10:21:13
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include <bits/stdc++.h>

using namespace std;

long long a,b,c,d,x,y,t;

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

int main()
{
    ifstream in("euclid3.in");
    ofstream out("euclid3.out");
    in >> t;
    for(int i=1;i<=t;i++){
        in >> a >> b >> c;
        gcd(a,b,&d,&x,&y);
        if(c%d) out << 0 << ' ' << 0 << '\n';
        else out << x*c/d << ' ' << y*c/d << '\n';
    }
}