Cod sursa(job #2445426)

Utilizator GeoeyMexicanuBadita George GeoeyMexicanu Data 4 august 2019 00:57:39
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.61 kb
#include <iostream>
#include <fstream>

using namespace std;

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

long a,b,c,x,y,d;
int n;

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

int main()
{
    f>>n;
    while(n!=0)
    {
        f>>a>>b>>c;
        euclid(a,b,d,x,y);
        if(c%d != 0)
            g<<0<<' '<<0<<'\n';
        else
            g<<x*(c/d)<<' '<<y*(c/d)<<'\n';
        n--;
    }
}