Cod sursa(job #1476215)

Utilizator akaprosAna Kapros akapros Data 24 august 2015 17:43:55
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.78 kb
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n, i, a, b, c;
int gcd(int &x, int &y)
{
    int c, x0, y0, d, z;
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    z = a / b;
    c = a;
    a = b;
    b = c % b;
    d = gcd(x0, y0);
    x = y0;
    y = x0 - z * y0;
    return d;
}
void read()
{
    int x, y, d;
    freopen("euclid3.in", "r", stdin);
    freopen("euclid3.out", "w", stdout);
    scanf("%d", &n);
    for (i = 1; i <= n; ++ i)
    {
        scanf("%d %d %d", &a, &b, &c);
        d = gcd(x, y);
        if (c % d != 0)
            printf("0 0\n");
        else
            printf("%d %d\n", x * (c / d) , y * (c / d));
    }
}
int main()
{
    read();
    return 0;
}