Cod sursa(job #3298865)

Utilizator blnsara_10Sara Balanescu blnsara_10 Data 2 iunie 2025 19:48:17
Problema Algoritmul lui Euclid extins Scor 100
Compilator c-64 Status done
Runda Arhiva educationala Marime 0.82 kb
#include <stdio.h>

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

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

    int t;
    fscanf(in, "%d", &t);

    while (t--)
    {
        long long a, b, c, x, y;
        fscanf(in, "%lld %lld %lld", &a, &b, &c);

        long long d = euclid(a, b, &x, &y);
        if (c % d != 0)
            fprintf(out, "0 0\n");
        else {
            x *= c / d;
            y *= c / d;
            fprintf(out, "%lld %lld\n", x, y);
        }
    }

    fclose(in);
    fclose(out);
    return 0;
}