about summary refs log tree commit diff
path: root/others/volume1/112.pas
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-21 21:09:39 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-02-21 21:09:39 +0700
commit7d19f480637e9e880b98dabfbcf8e885b0a2d3b9 (patch)
treefa52914a2e58bc13570839fa297be05b7b7616bf /others/volume1/112.pas
parentf2d4bc6b7c302dee2d84a3acf84b83b5a98c45fa (diff)
downloadcp-7d19f480637e9e880b98dabfbcf8e885b0a2d3b9.tar.gz
Update others/volume1
Diffstat (limited to 'others/volume1/112.pas')
-rw-r--r--others/volume1/112.pas39
1 files changed, 39 insertions, 0 deletions
diff --git a/others/volume1/112.pas b/others/volume1/112.pas
new file mode 100644
index 0000000..0dec65e
--- /dev/null
+++ b/others/volume1/112.pas
@@ -0,0 +1,39 @@
+uses clib;
+
+var
+  a, b: int64;
+  i, j: int32;
+  p: array[2..999983] of boolean;
+  primes: intar;
+
+begin
+  for i := 2 to 999983 do
+    p[i] := true;
+  for i := 2 to 997 do
+    for j := 2 to 999983 div i do
+      p[i * j] := false;
+  j := 0;
+  setlength(primes, 78498);
+  for i := 2 to 999983 do
+    if p[i] then
+      begin
+        primes[j] := i;
+        inc(j)
+      end;
+
+  repeat
+    readln(a, b);
+    a := a * b div sqr(gcd(a, b));
+    b := 0;
+    for i := 0 to bisect_left(primes, trunc(sqrt(a))) do
+      while a mod primes[i] = 0 do
+        begin
+          a := a div primes[i];
+          b := b + 1
+        end;
+    if a = 1 then
+      writeln(b)
+    else
+      writeln(b + 1)
+  until eof(input)
+end.