Cod sursa(job #3358339)

Utilizator Radulescu_BiancaRadulescu Bianca-Larisa Radulescu_Bianca Data 16 iunie 2026 13:23:01
Problema Algoritmul lui Euclid extins Scor 100
Compilator c-64 Status done
Runda Arhiva educationala Marime 1.08 kb
#include <stdio.h>

void euclid_extins(long long a, long long b, long long *d, long long *x, long long *y) {
    if (b == 0) {
        *d = a;
        *x = 1;
        *y = 0;
    } else {
        long long x1, y1;
        euclid_extins(b, a % b, d, &x1, &y1);
        *x = y1;
        *y = x1 - (a / b) * y1;
    }
}

int main() {
    FILE *fin = fopen("euclid3.in", "r");
    FILE *fout = fopen("euclid3.out", "w");

    if (fin == NULL || fout == NULL) {
        return 0;
    }

    int T;
    if (fscanf(fin, "%d", &T) == 1) {
        while (T--) {
            long long A, B, C;
            if (fscanf(fin, "%lld %lld %lld", &A, &B, &C) == 3) {
                long long d, x, y;
                euclid_extins(A, B, &d, &x, &y);

                if (C % d != 0) {
                    fprintf(fout, "0 0\n");
                } else {
                    x *= (C / d);
                    y *= (C / d);
                    fprintf(fout, "%lld %lld\n", x, y);
                }
            }
        }
    }

    fclose(fin);
    fclose(fout);
    return 0;
}