Cod sursa(job #2070387)

Utilizator amaliarebAmalia Rebegea amaliareb Data 19 noiembrie 2017 15:13:18
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <fstream>
#include <iostream>
#include <cstring>
#include <unordered_map>
#include <map>
#include <bitset>

using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int a, b, c, x, y, d, T;

void euclid(int a, int b)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
        d = a;
    }
    else
    {
        int x0, y0;
        euclid(b, a % b);
        x0 = x;
        y0 = y;
        x = y0;
        y = x0 - (a/b) * y0;
    }
}

int main()
{
    f >> T;
    while (T)
    {
        f >> a >> b >> c;
        euclid(a, b);
        cout << d << '\n';
        if(c % d == 0) g << x * (c / d) << ' ' << y * (c / d) << '\n';
        else g << "0 0\n";
        T--;
    }
    return 0;
}