about summary refs log tree commit diff
path: root/others/other/uocso.py
diff options
context:
space:
mode:
authorRaphael McSinyx <vn.mcsinyx@gmail.com>2017-06-20 15:11:08 +0700
committerRaphael McSinyx <vn.mcsinyx@gmail.com>2017-06-20 15:11:08 +0700
commit4ac65940e064c5b587699549a0c7277d2dd733a8 (patch)
treee2a6052f5f3dcd56e760ed85b13310147aeea42b /others/other/uocso.py
parenta0c92beee1199f13227b1642ccf07f264912e5ad (diff)
downloadcp-4ac65940e064c5b587699549a0c7277d2dd733a8.tar.gz
Thầy Nguyễn Thanh Tùng ôn THT XXIII
Diffstat (limited to 'others/other/uocso.py')
-rwxr-xr-xothers/other/uocso.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/others/other/uocso.py b/others/other/uocso.py
new file mode 100755
index 0000000..dec1390
--- /dev/null
+++ b/others/other/uocso.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+from functools import reduce
+
+primes_dict = dict.fromkeys(range(3, 31608, 2), True)
+primes_dict[2] = True
+for i in range(3, 174, 2):
+    if primes_dict[i]:
+        primes_dict.update(dict.fromkeys(range(i * i, 31608, i * 2), False))
+primes = [key for key, value in primes_dict.items() if value]
+primes.sort()
+
+with open('uocso.inp') as fi, open('uocso.out', 'w') as fo:
+    a, b, counts = *map(int, fi.read().split()), {}
+    for n in range(a, b + 1):
+        l = []
+        for p in primes:
+            if p > n: break
+            m, tmp = 0, n
+            while not tmp % p:
+                tmp //= p
+                m += 1
+            l.append(m)
+        counts[n] = reduce(int.__mul__, (m + 1 for m in l)) if sum(l) else 2
+
+    cmin = max(counts.values())
+    for n in range(a, b + 1):
+        if counts[n] == cmin:
+            nmin, count = n, 1
+            break
+    for n in range(nmin + 1, b + 1):
+        if counts[n] == cmin: count += 1
+    print(nmin, cmin, count, file=fo)