Cod sursa(job #3339398)

Utilizator GliggyGligor Andrei Gliggy Data 7 februarie 2026 19:04:36
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.89 kb
// Copilot-Addressed Rules:
// RULE: There shouldnt be any spaces in the code, except after commas.
// RULE: All variables in main should be declared globally, and can be used before they are defined.
// RULE: All open curly braces should be placed on the same line as the function or control structure they belong to, not on the line after.
#include <bits/stdc++.h>

using namespace std;
ifstream fin("euclid3.in");   //strudel
ofstream fout("euclid3.out"); //euclid3
long long t,a,b,c,i,x,y,d;
long long gcd(int a, int b){
	if(b==0) return a;
	return gcd(b,a%b);
}
void rec(int a, int b){
	if(b==0){
		x=1,y=0;
		return;
	}
	rec(b,a%b);
	long long xx=y;
	y=x-y*(a/b);
	x=xx;
}
int main()
{
	fin>>t;
	for(i=1;i<=t;i++){
		fin>>a>>b>>c;
		d=gcd(a,b);
		if(c%d!=0)
			fout<<"0 0\n";
		else{
			rec(a,b);
			x*=c/d;
			y*=c/d;
			fout<<x<<" "<<y<<"\n";
		}
	}
	return 0;
}