about summary refs log tree commit diff
path: root/09/TP-HN-2014/cau1.pas
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-09 10:47:37 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-01-09 10:47:37 +0700
commit318184dbda0658d8afae6dd3c13a0718382726a1 (patch)
tree5a62259a03200cd77823431994fe3479e5d7461f /09/TP-HN-2014/cau1.pas
parent15b38076cc08d89024864252e99e10fe6f597196 (diff)
downloadcp-318184dbda0658d8afae6dd3c13a0718382726a1.tar.gz
Add NTU/{pali2,editpic}.c and update README.md
Diffstat (limited to '09/TP-HN-2014/cau1.pas')
-rw-r--r--09/TP-HN-2014/cau1.pas46
1 files changed, 46 insertions, 0 deletions
diff --git a/09/TP-HN-2014/cau1.pas b/09/TP-HN-2014/cau1.pas
new file mode 100644
index 0000000..466d4c4
--- /dev/null
+++ b/09/TP-HN-2014/cau1.pas
@@ -0,0 +1,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.