Cod sursa(job #2228042)

Utilizator Bulboaca_EugenBulboaca Alexandru Eugen Bulboaca_Eugen Data 2 august 2018 16:06:56
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.73 kb
#include <bits/stdc++.h>
using namespace std;
void euclid_extins(long long a, long long b, long long &x, long long &y, long long &d){
    if(b == 0){
        x = 1;
        y = 0;
        d = a;
        return ;
    }
    euclid_extins(b, a%b, x, y, d);
    long long newx = y;
    long long newy = x - y*(a/b) ;
    x = newx;
    y = newy;
}
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int main()
{
    int n;
    fin >> n;
    for(int i = 1; i <= n; ++i){
        long long a, b, c, x, y, d;
        fin >> a >> b >> c;
        euclid_extins(a, b, x, y, d);
        if(c % d != 0)
            fout << "0 0\n";
        else fout << x * (c / d) << " " << y * (c / d) << '\n';
    }
    return 0;
}