1
0
Fork 0

Reformat for karma

This commit is contained in:
Nguyễn Gia Phong 2019-06-24 21:11:13 +07:00
parent 27d4089726
commit 0c84539e60
1 changed files with 6 additions and 8 deletions

14
THT/B/QG-2016/remainder.py Normal file → Executable file
View File

@ -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)