Cod sursa(job #3251877)

Utilizator Alin031Ulici Alin Alin031 Data 27 octombrie 2024 16:49:15
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.77 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
#define lint long long
int gcd(lint a,lint b){
    while(b){
        int r=a%b;
        a=b;
        b=r;
    }
    return a;
}
void ee(lint &x,lint &y,lint a,lint b){
    if(!b){
        x=1;
        y=0;
    }
    else{
        ee(x,y,b,a%b);
        lint aux=x;
        x=y;
        y=aux-y*(a/b);
    }
}
lint a,b,c,d,t;
int main()
{
    fin>>t;
    for(int i=1;i<=t;i++){
        fin>>a>>b>>c;
        lint r1,r2;
        ee(r1,r2,a,b);
        d=gcd(a,b);
        if(c%d==0){
            fout<<r1*(c/d)<<' '<<r2*(c/d)<<'\n';
        }
        else{
            fout<<0<<' '<<0<<'\n';
        }
    }
    return 0;
}