Cod sursa(job #3164791)

Utilizator ArklahhisCraciun Mihai Arklahhis Data 4 noiembrie 2023 12:01:14
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.09 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
#define MAX 2000000000
#define MIN -2000000000
long long r,a,b,c,x,y,n,d;
void euclid(long long a, long long b, long long &x, long long &y)
{
    if (b==0)
    {
        x=1;
        y=0;
    }
    else
    {
        long long x0,y0;
        euclid(b,a%b,x0,y0);
        x=y0;
        y=x0-y0*(a/b);
    }
}
int main()
{
    fin >> n;
    for (int i=1; i<=n; i++)
    {
        fin >> a >> b >> c;
        euclid(a,b,x,y);
        d=a*x+b*y;
        if (x>MAX || x<MIN || y>MAX || y<MIN)
            fout << 0 << " " << 0 << '\n';
        else
        {
            if (c%d!=0)
                fout << 0 << " " << 0 << '\n';
            else
            {
                r=c/d;
                x*=r;
                y*=r;
                if (x>MAX || x<MIN || y>MAX || y<MIN)
                    fout << 0 << " " << 0 << '\n';
                else
                    fout << x << " " << y << '\n';
            }
        }
    }
    return 0;
}