about summary refs log tree commit diff
path: root/THT
diff options
context:
space:
mode:
Diffstat (limited to 'THT')
-rwxr-xr-x[-rw-r--r--]THT/B/QG-2016/remainder.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/THT/B/QG-2016/remainder.py b/THT/B/QG-2016/remainder.py
index c70faba..6cef9df 100644..100755
--- a/THT/B/QG-2016/remainder.py
+++ b/THT/B/QG-2016/remainder.py
@@ -1,5 +1,4 @@
 #!/usr/bin/env python3
-
 TESTS = [
     [12, 3, 8],
     [2, 15, 17],
@@ -15,8 +14,7 @@ TESTS = [
     [2016, 666666666666666, 8888888888],
     [11223344, 555666777888999, 1357924680],
     [999999999999999967, 999999999999999877, 999999999999999989],
-    [123456789123456789, 123456789123456789, 987654321123456789]
-]
+    [123456789123456789, 123456789123456789, 987654321123456789]]
 
 # Gọi l là "chiều dài" của x, l = int(log10(x) + 1) hay l = len(str(x))
 # Đặt l ** 10 = a, dễ thấy y = x * (a**(n-1) + a**(n-2) + ... + a + 1)
@@ -26,8 +24,8 @@ TESTS = [
 #                      <=> q = x * (a**n - 1) % (a*m - a) / (a - 1)
 
 with open('REMAINDER.TXT', 'w') as f:
-    for case in TESTS:
-        a = 10 ** len(str(case[0]))
-        case[2] *= a - 1
-        p = pow(a, case[1], case[2])
-        f.write(str(case[0] * (p - 1) % case[2] // (a - 1)) + '\n')
+    for x, n, m in TESTS:
+        a = 10 ** len(str(x))
+        m *= a - 1
+        p = pow(a, n, m)
+        print(x * (p - 1) % m // (a - 1), file=f)