Cod sursa(job #2455134)

Utilizator andreisophieMMAndrei Maruntis andreisophieMM Data 10 septembrie 2019 20:38:32
Problema Algoritmul lui Euclid extins Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <fstream>

using namespace std;

ifstream f("euclid3.in");
ofstream g("euclid3.out");

void cmmdcE(int a, int b, int &d, int &x, int &y)
{
    int x0, y0;
    if (b==0)
    {
        d=a;
        x=1;
        y=0;
    }
    else
    {
        cmmdcE(b,a%b,d,x0,y0);
        x=y0;
        y=x0-(a/b)*y0;
    }
}

void Diofantic(int a, int b, int c)
{
    int d,x0,y0;
    cmmdcE(a,b,d,x0,y0);
    if (c%d==0)
        g<<x0*c/d<<' '<<y0*c/d<<'\n';
    else
        g<<"0 0\n";
}

int main()
{
    int n,a,b,c;
    f>>n;
    for (int i=0;i<n;i++)
    {
        f>>a>>b>>c;
        Diofantic(a,b,c);
    }
    return 0;
}