Cod sursa(job #2900516)

Utilizator stalecuAlecu Stefan-Iulian stalecu Data 10 mai 2022 23:32:44
Problema Algoritmul lui Euclid extins Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.79 kb
program euclid3;

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

function Euclid3(a, b: longint; var x, y: longint): integer;
var
  x0, y0: longint;
begin
  if b = 0 then
  begin
    x := 1;
    y := 0;
    Euclid3 := a;
  end
  else
  begin
    Euclid3 := Euclid3(b, a mod b, x0, y0);
    x := y0;
    y := x0 - (a div b) * y0;
  end;
end;

const
  C_IN_FNAME = 'euclid3.in';
  C_OUT_FNAME = 'euclid3.out';
var
  fin, fout: text;
  n, a, b, c, d, x, y, i: longint;
begin
  AssignFile(fin, C_IN_FNAME); Reset(fin);
  AssignFile(fout, C_OUT_FNAME); Rewrite(fout);
  Read(fin, n);
  for i := 1 to n do
  begin
    Read(fin, a, b, c);
    d := Euclid3(a, b, 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.