Cod sursa(job #1376212)

Utilizator Al3ks1002Alex Cociorva Al3ks1002 Data 5 martie 2015 16:34:40
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.09 kb
#include<cstdio>
#include<fstream>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<bitset>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<unordered_map>

#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

using namespace std;

int t, a, b, c, d, x, y;

void gcd(int a, int b)
{
    if(b == 0)
    {
        d = a;
        x = 1;
        y = 0;
        return;
    }

    gcd(b, a % b);

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

    x = x0;
    y = y0;
}

int main()
{
    freopen("euclid3.in", "r", stdin);
    freopen("euclid3.out", "w", stdout);

    scanf("%d", &t);

    for(; t; t--)
    {
        scanf("%d%d%d", &a, &b, &c);

        d = 0;
        gcd(a, b);

        if(c % d) printf("0 0\n");
        else printf("%d %d\n", x * (c / d), y * (c / d));
    }

    return 0;
}