Cod sursa(job #3223940)

Utilizator catalinaionela77Catalina Ionela Florescu catalinaionela77 Data 14 aprilie 2024 10:36:58
Problema Algoritmul lui Euclid extins Scor 0
Compilator c-64 Status done
Runda Arhiva educationala Marime 0.89 kb
#include <stdio.h>
#include <stdlib.h>

typedef long long ll;

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

int main() {
    FILE *f1=fopen("euclid3.in", "r"),*f2=fopen("euclid3.out", "w");
    if(!f1||!f2)
    {
        perror(NULL);
        return 1;
    }

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

    while (t) {
        ll a, b, c;
        fscanf(fin, "%lld %lld %lld", &a, &b, &c);

        ll x, y;
        ll d = gcd(a, b, &x, &y);

        if (c % d != 0) {
            fprintf(fout, "0 0\n");
        } else {
            ll factor = c / d;
            fprintf(fout, "%lld %lld\n", x * factor, y * factor);
        }
        t--;
    }

    fclose(f1);
    fclose(f2);
    return 0;
}