Cod sursa(job #1132603)

Utilizator Cosmin1490Balan Radu Cosmin Cosmin1490 Data 3 martie 2014 18:07:19
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.66 kb
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <iterator>
#include <random>
#include <assert.h>
using namespace std;

const string file = "euclid3";

const string infile = file + ".in";
const string outfile = file + ".out";

const int INF = 0x3f3f3f3f; 

//#define ONLINE_JUDGE

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

int main()
{
#ifdef ONLINE_JUDGE
	ostream &fout = cout;
	istream &fin = cin;
#else
	fstream fin(infile.c_str(), ios::in);
	fstream fout(outfile.c_str(), ios::out);
#endif	

    int T;
    fin >> T;
    for(int t = 0; t < T; t++)
    {
        int a, b, c;
        fin >> a >> b >> c;
        int d, x, y;
        d = euclidExtins(a, b, x, y);
        if(c % d == 0)
        {
            x *= c / d;
            y *= c / d;
        }
        else
        {
            x = y = 0;
        }
        fout << x << " " << y << "\n";
    }
#ifdef ONLINE_JUDGE
#else
    fout.close();
	fin.close();
#endif
}