Cod sursa(job #1484246)

Utilizator bogdan10bosBogdan Sitaru bogdan10bos Data 10 septembrie 2015 17:14:37
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.89 kb
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>

#define INF ( (1 << 30) - 1 + (1 << 30) )
#define mod 666013

using namespace std;

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

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

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

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

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

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

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

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

    return 0;
}