From 0c84539e6040bdb918a1d0e386f033da17170348 Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Mon, 24 Jun 2019 21:11:13 +0700 Subject: Reformat for karma --- THT/B/QG-2016/remainder.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) mode change 100644 => 100755 THT/B/QG-2016/remainder.py diff --git a/THT/B/QG-2016/remainder.py b/THT/B/QG-2016/remainder.py old mode 100644 new mode 100755 index c70faba..6cef9df --- 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) -- cgit 1.4.1