Cod sursa(job #1898149)

Utilizator CammieCamelia Lazar Cammie Data 1 martie 2017 20:48:28
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.98 kb
#include <stdio.h>

#define InFile "euclid3.in"
#define OutFile "euclid3.out"

using namespace std;

FILE *fin, *fout;

void Euclid(int a, int b, int &d, long long &x, long long& y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        d = a;
    }
    else
    {
        long long x0, y0;

        Euclid(b, a % b, d, x0, y0);

        x = y0;
        y = x0 - (a / b) * y0;
    }
}

void Read()
{
    int t, a, b, d, c;
    long long x, y;

    fscanf(fin, "%d", &t);

    for (int i = 1; i <= t; i++)
    {
        fscanf(fin, "%d %d %d", &a, &b, &c);

        Euclid(a, b, d, x, y);

        if (c % d == 0)
        {
            x *= c / d;
            y *= c / d;

            fprintf(fout, "%lld %lld\n", x, y);
        }
        else
            fprintf(fout, "%d %d\n", 0,0);

    }
}

int main()
{
    fin = fopen(InFile, "rt");
    fout = fopen(OutFile, "wt");

    Read();

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