Cod sursa(job #1410311)

Utilizator Al3ks1002Alex Cociorva Al3ks1002 Data 30 martie 2015 23:32:16
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.1 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 a, b, c, t, d, x, y;

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

    gcd(b, a % b);

    int x0 = x;
    int y0 = y;

    x = y0;
    y = x0 - (a / b) * 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);

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

    return 0;
}