Cod sursa(job #443196)

Utilizator ncbllrNegrii Costin ncbllr Data 16 aprilie 2010 12:59:46
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
int c,d,n,e;


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

int main()
{	
	int i;
	ifstream f("euclid3.in");
//	freopen("euclid3.out","w",stdout);
	
	f>>n;
	
	for( int i = 1; i <= n; ++i)
	{	
		int a, b, c, d, x, y;
		f>>a>>b>>c;
		
		euclid(a,b,d,x,y);
		if ( abs(c) % abs(d) == 0) 
			cout<<x * (c / d)<<" "<<y * ( c / d)<<endl;
		else 
			cout<<"0 0"<<endl;
			   
	}
       
       
   return 0;          
}