Cod sursa(job #2595883)

Utilizator CharacterMeCharacter Me CharacterMe Data 8 aprilie 2020 16:30:45
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.83 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("euler3.in");
ofstream fout("euler3.out");

int t, a, b, c, d, x, y, x0, y0;
bool swapped;

void cmmdc(int a, int b);

int main()
{
    fin >> t;
    while(t--){

        fin >> a >> b >> c;
        if(a < b) {
            swap(a, b);
            swapped = true;
        }
        else swapped = false;

        cmmdc(a, b);

        if(swapped) {
            swap(x, y);
            swap(a, b);
        }

        if(c % d) fout << "0 0\n";
        else fout << c / d * x << " " << c / d * y << "\n";

    }
    return 0;
}

void cmmdc(int a, int b){
    if(!b){
        d = a;
        x = 1;
        y = 0;
    }
    else{
        cmmdc(b, a % b);

        x0 = y;
        y0 = x - a / b * y;
        x = x0;
        y = y0;
    }
}