Cod sursa(job #3358285)

Utilizator Crisan_AndreiCrisan Paul-Andrei Crisan_Andrei Data 16 iunie 2026 02:28:10
Problema Algoritmul lui Euclid extins Scor 100
Compilator c-64 Status done
Runda Arhiva educationala Marime 1.21 kb
#include <stdio.h>
#include <stdlib.h>

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

int main(void) 
{
    FILE *in = fopen("euclid3.in", "r");
    FILE *out = fopen("euclid3.out", "w");
    int t;
    fscanf(in, "%d", &t);
    while (t > 0) 
    {
        long long a, b, c;
        fscanf(in, "%lld %lld %lld", &a, &b, &c);
        if (a == 0 && b == 0) 
        {
            fprintf(out, "0 0\n");
            t--;
            continue;
        }
        long long a1 = abs(a);
        long long b1 = abs(b);
        long long d, x0, y0;
        euclind(a1, b1, &d, &x0, &y0);
        if (c % d != 0)
            fprintf(out, "0 0\n");
        else 
        {
            long long f = c / d;
            long long x = x0 * f;
            long long y = y0 * f;
            if (a < 0) 
                x = -x;
            if (b < 0) 
                y = -y;
            fprintf(out, "%lld %lld\n", x, y);
        }
        t--;
    }
    return 0;
}