Cod sursa(job #2201589)

Utilizator cristian.pavelPavel Cristian cristian.pavel Data 5 mai 2018 10:56:41
Problema Algoritmul lui Euclid extins Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include <iostream>
#include <stdio.h>
using namespace std;

void euclid(long a, long b, long *d, long *x, long *y) {

    if (b == 0) {
        *x = 1;
        *y = 0;
        *d = a;
    } else {
        long x0, y0;
        euclid (b, a % b, d, &x0, &y0);
        *x = y0;
        *y = x0 - (a / b) * y0;
    }


}

int main() {

    FILE *in, *out;
    in = fopen("euclid3.in", "rt");
    out = fopen("euclid3.out", "wt");
    int T;
    long a, b, c;
    fscanf(in,"%d", &T);

    while (T > 0) {
        fscanf(in, "%ld %ld %ld", &a, &b, &c);

        long d, x, y;
        euclid(a, b, &d, &x, &y);

        if (c % d != 0) {

            fprintf(out, "0 0\n");

        } else {
            x = x * c / d;
            y = y * c / d;

            fprintf(out, "%ld %ld\n", x, y);

        }
        T--;
    }


    return 0;
}