Cod sursa(job #2589176)

Utilizator GiosinioGeorge Giosan Giosinio Data 25 martie 2020 21:21:47
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.7 kb
#include <fstream>

using namespace std;

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

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

int main(){
    int T, a, b, c;
    f>>T;
    for(int i=1; i<=T; i++){
        f>>a>>b>>c;
        int d; long long *x = new long long, *y = new long long;
        EuclidExtins(a,b,d,x,y);
        if(c % d == 0)
            g<<*x * (c/d)<<" "<<*y * (c/d)<<"\n";
        else
            g<<0<<" "<<0<<"\n";
    }
}