diff options
author | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2019-06-24 21:11:13 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2019-06-24 21:11:13 +0700 |
commit | 0c84539e6040bdb918a1d0e386f033da17170348 (patch) | |
tree | b50a937ce1d3f275573d211297236eefb4638311 /THT/B | |
parent | 27d4089726131b1b63dd4bc5592076c8153acdd3 (diff) | |
download | cp-0c84539e6040bdb918a1d0e386f033da17170348.tar.gz |
Reformat for karma
Diffstat (limited to 'THT/B')
-rwxr-xr-x[-rw-r--r--] | THT/B/QG-2016/remainder.py | 14 |
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) |