Cod sursa(job #1984653)

Utilizator ruxandramateiMatei Ruxandra ruxandramatei Data 25 mai 2017 17:02:20
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.75 kb
#include <iostream>
#include <fstream>
#include <assert.h>

using namespace std;

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

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 n;
  in>>n;
  for(int i=1;i<=n;i++){
    int x = 0, y= 0,d=0;
    int a, b , c;
    bool ok = false;
    in>>a>>b>>c;
    assert( -1000000000 <= a && a <= 1000000000 );
    assert( -1000000000 <= b && b <= 1000000000 );
    assert( -2000000000 <= c && c <= 2000000000 && c != 0 );

    euclid(a,b,d,x,y);
    x = x*(c/d);
    y= y*(c/d);
    if(c%d)
      out<<"0 0\n";
    else out<<x<<' '<<y<<'\n';
  }
  return 0;
}