Cod sursa(job #2939298)

Utilizator PsyDuck1914Feraru Rares-Serban PsyDuck1914 Data 13 noiembrie 2022 14:05:53
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.63 kb
#include <fstream>
#include <iostream>

using namespace std;

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

void euclid(int a, int b, int &d, int &x, int &y){
    if(b == 0){
        d = a;
        x = 1;
        y = 0;
        return;
    }
    int x_, y_;
    euclid(b, a - a/b*b, d, x_, y_);
    x = y_;
    y = x_ - (a/b)*y_;
}

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

    return 0;
}