about summary refs log tree commit diff
path: root/09/TP-HN-2014/cau1.pas
blob: 466d4c4035351ac0215979c353667977ff4ecf5a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var
  f: text;
  a, b, g: int64;
  c, d: smallint;


function gcd(x, y: int64): int64;
  var z: int64;

  begin
    while y <> 0 do
      begin
        z := y; 
        y := x mod y;
        x := z
      end;

    gcd := a
  end;


begin
  assign(f, 'CAU1.INP');
  reset(f);
  read(f, a, b, c, d);
  close(f);

  a := a * d - c * b;
  b := b * d;

  g := gcd(a, b);

  a := a div g;
  b := b div g;

  if b < 0 then
    begin
      a := -a;
      b := -b
    end;

  assign(f, 'CAU1.OUT');
  rewrite(f);
  writeln(f, a, ' ', b);
  close(f)
end.