Cod sursa(job #1379470)

Utilizator taigi100Cazacu Robert taigi100 Data 6 martie 2015 18:01:27
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.99 kb
/*
    Keep It Simple!
*/

#include <fstream>
#include <vector>
#include <list>
#include <stack>
#include <string>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

ifstream f("euclid3.in");
ofstream g("euclid3.out");

#define ll long long
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

void Solve()
{
    int t,x,y,c,d;
    f >> t;
    while(t--)
    {
        f >> x >> y >> c;
        int d,a,b;
        cmmdc(x,y,d,a,b);
        if(c%d)
            g << "0 0\n";
        else
            g << (c/d)*a << ' ' << (c/d)*b << '\n';
    }
}

int main()
{
    Solve();
    return 0;
}