Cod sursa(job #3298453)

Utilizator Bolbotina_David-AndreiBolbotina David-Andrei Bolbotina_David-Andrei Data 30 mai 2025 10:56:01
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.95 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <fstream>
using namespace std;

ifstream fin("euclid3.in");
ofstream fout("euclid.out");

int euclid_extins(int &x, int &y, int a, int b)
{
	if(!b)
	{
	    x = 1;
		y = 0;
		return a;
	}
	else
	{
	    int d, x1, y1;
		d = euclid_extins (x1, y1, b, a % b);
		x = y1;
		y = x1 - y1 * (a / b);
		return d;
	}
}

int main() {

	int n,a,b,c,d,x,y;
	fin>>n;
	while(n){
    	fin>>a>>b>>c;
    	d = euclid_extins(x,y,a,b);
    	if (c % d)
    			fout<<"0 0\n";
    		else
    			fout<<x * (c / d)<<" "<<y * (c / d)<<"\n";
    	n--;
	}
	return 0;
}