Cod sursa(job #2723256)

Utilizator BogdanRazvanBogdan Razvan BogdanRazvan Data 13 martie 2021 19:59:24
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.88 kb
#include <bits/stdc++.h>

using namespace std;

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

void usain_bolt()
{
    ios::sync_with_stdio(false);
    fin.tie(0);
}

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

int main()
{
    usain_bolt();

    long long tt;

    fin >> tt;
    for(; tt; --tt) {
        long long a, b, c;

        fin >> a >> b >> c;
        long long x, y;
        long long ans = euclid(a, b, x, y);
        if(c % ans == 0) {
            fout << x * c / ans << " " << y * c / ans << "\n";
        }
        else {
            fout << 0 << " " << 0 << "\n";
        }
    }
    return 0;
}