Cod sursa(job #2097137)

Utilizator Iorgus08Iorgus Serghei Cicala Iorgus08 Data 30 decembrie 2017 16:22:58
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int T;
void euclid(int a, int b, int &d, int &x, int &y)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
        d = a;
    }
    else
    {
        int x0, y0;
        euclid(b, a % b, d, x0, y0);
        x = y0;
        y = x0 - (a / b) * y0;
    }
}
int main()
{
    fin >> T;
    int d, x, y, a, b, c;
    for(int t = 1; t <= T; t++)
    {
        fin >> a >> b >> c;
        euclid(a, b, d, x, y);
        if(c % d == 0)
            fout << 1LL * x * c / d << " " << 1LL * y * c / d;
        else fout << 0 << " " << 0;
        fout << '\n';
    }
    return 0;
}