Cod sursa(job #2909726)

Utilizator TheGarbageWeebIonescu Ioan-Andrei TheGarbageWeeb Data 14 iunie 2022 22:51:15
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
void euclid(long int a, long int b,long int &d, long int& x, long int& y)
{
    if (b == 0)
    {
        d = a;
        x = 1, y = 0;
    }
    else
    {
        long int x1, y1;
        euclid(b, a % b, d,x1, y1);
        x = y1;
        y = x1 - a / b * y1;
    }
}

int main()
{
    long int a, b, c, d, x = 0, y = 0;
    int n;
    in >> n;
    for ( int i = 0; i < n; i++)
    {
    in >> a >> b >> c;
    euclid(a, b, d, x, y);
    if (c % d)
        out << "0 0" << endl;
    else
        out << x * c / d << " " << y * (c / d)<<endl;
}
}