Cod sursa(job #2784664)

Utilizator teomarsTeodora Sintea teomars Data 16 octombrie 2021 23:13:12
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <iostream>
#include <fstream>

using namespace std;

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

long long a, b, c, n;

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

int main()
{
    fin>>n;
    for(int i=0; i<n; i++){
        fin>>a>>b>>c;
        long long x=1, y=0, d;
        euclid(a, b, x, y, d);
        if(c%d)
            fout<<0<<' '<<0<<'\n';
        else
            fout<<x<<' '<<y<<'\n';
    }
    return 0;
}