Cod sursa(job #1404522)

Utilizator mirceadinoMircea Popoveniuc mirceadino Data 28 martie 2015 12:26:26
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.23 kb
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

#ifdef HOME
const string inputFile = "input.txt";
const string outputFile = "output.txt";
#else
const string problemName = "euclid3";
const string inputFile = problemName + ".in";
const string outputFile = problemName + ".out";
#endif

typedef long long int lld;

int N;

int gcd(int a, int b, lld &x, lld &y) {
    if(!b) {
        x = 1;
        y = 0;
        return a;
    }

    lld x0, y0;
    int d;

    d = gcd(b, a % b, x0, y0);

    x = y0;
    y = x0 - y0 * (a / b);

    return d;
}

int main() {
    int a, b, c, d;
    lld x, y;

#ifndef ONLINE_JUDGE
    freopen(inputFile.c_str(), "r", stdin);
    freopen(outputFile.c_str(), "w", stdout);
#endif

    scanf("%d", &N);

    while(N--) {
        scanf("%d%d%d", &a, &b, &c);

        d = gcd(a, b, x, y);

        if(c % d) x = y = 0;
        else x *= (c / d), y *= (c / d);

        printf("%lld %lld\n", x, y);
    }

    return 0;
}