Cod sursa(job #168125)

Utilizator fogabFodor Gabor fogab Data 30 martie 2008 19:56:50
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
#include <iostream.h>
#include <stdio.h>
#include <fstream.h>

inline int get(int a,int b,int &x,int &y){
  
  if (b == 0){
    x = 1;
    y = 0;
    return a;
    }
  
  int x0,y0,k, sol;
  
  sol = get(b,a%b,x0,y0);
  
  k = a/b;  
  x = y0;
  y = x0 - k*y0;
  
  return sol;
}

int main(void){

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

int t,x,y,r,a,b;

for (fin >> t;t;t--){
    fin >> a >> b >> r;
    int cmmdc = get(a,b,x,y);
    if (r % cmmdc == 0) fout << x*(r/cmmdc) << " " << y*(r/cmmdc) << "\n";
      else fout << "0 0\n";
    }
fin.close();
fout.close();

return 0;    
}