Cod sursa(job #2900513)

Utilizator stalecuAlecu Stefan-Iulian stalecu Data 10 mai 2022 23:26:05
Problema Algoritmul lui Euclid extins Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.81 kb
program euclid3;

{$MODE objfpc}{$H+}{$J-}
uses sysutils;

procedure Euclid3(a, b: longint; out d: longint; out x: longint; out y: longint);
var
  newX, newY: longint;
begin
  if b = 0 then
  begin
    d := a;
    x := 1;
    y := 0;
  end
  else
  begin
  Euclid3(b, a mod b, d, x, y);
  newX := y;
  newY := x - y * (a div b);
  x := newX;
  y := newY;
  end;
end;

const
  C_IN_FNAME = 'euclid3.in';
  C_OUT_FNAME = 'euclid3.out';
var
  fin, fout: text;
  n, a, b, c, d, x, y : longint;
begin
  Assign(fin, C_IN_FNAME); Reset(fin);
  Assign(fout, C_OUT_FNAME); Rewrite(fout);
  read(fin, n);
  while not Eof(fin) do
  begin
    read(fin, a, b, c);
    euclid3(a, b, d, x, y);
    if c mod d=0 then
      Writeln(fout, x * (c div d), ' ', y * (c div d))
    else
      Writeln(fout, '0 0');
  end;

  Close(fin); Close(fout);
end.