Cod sursa(job #2685910)

Utilizator TheGodYatoBUGNAR CATALIN TheGodYato Data 17 decembrie 2020 23:55:59
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.58 kb
#include <iostream>
#include <fstream>
using namespace std;
fstream fin("euclid3.in");
ofstream fout("euclid3.out");

void euclid(int a,int b,int &d,int &x,int &y)
{
    if(b==0)
    {
        x=1;
        y=0;
        d=a;
    }
    else{
        int x0,y0;
        euclid(b,a%b,d,x0,y0);
        x=y0;
        y=x0-(a/b)*y0;
    }
}
int main()
{
    int n,a,b,c,x,y,d;
    fin>>n;
    for(;n;--n)
    {
        fin>>a>>b>>c;
        euclid(a,b,d,x,y);
        if(c%d==0)fout<<x*(c/d)<<" "<<y*(c/d)<<'\n';
        else fout<<"0 0"<<'\n';
    }
    return 0;
}