Cod sursa(job #2230272)

Utilizator nicolaefilatNicolae Filat nicolaefilat Data 9 august 2018 16:47:01
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <iostream>
#include <fstream>

using namespace std;

typedef long long ll;

ifstream in("euclid3.in");
ofstream out("euclid3.out");

void euclid_extins(ll &x,ll &y,ll a,ll b,ll &d){

    if(b == 0){
        d = a;
        x = 1;
        y = 0;
        return;
    }

    euclid_extins(x,y,b,a % b,d);
    ll newx = y;
    ll newy = x - y*(a/b);
    x = newx;
    y = newy;
}


int main()
{
    int n;
    in>>n;
    for(int i = 1; i <= n; i++){
        ll a,b,c,d,x,y;
        in>>a>>b>>c;
        euclid_extins(x,y,a,b,d);

        if(c % d != 0)
            out<<0<<" "<<0;
        else
            out<<x * (c/d)<<" "<<y * (c/d);

        out<<"\n";
    }


    return 0;
}