Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import zip_longest
- remainder = 5
- n_dividend = 4 # 被除数
- n_divisor = 1 # 除数
- n_quotient = 3 # 商
- steps = (
- # q_offset q, e_offset e
- ((2, 1), (1, 2)),
- ((1, 1), (0, 2)),
- ((0, 1), (-1, 0)),
- )
- def gen_steps(e, s, q):
- n_dividend = len(str(e))
- n_quotient = len(str(q))
- i = n_quotient - 1
- tmp = int(str(e)[:n_dividend-n_quotient+1])
- while i > 0:
- m = int(str(q)[n_quotient - i - 1]) * s
- n = int(str(tmp - m) + str(e)[n_dividend - i-1])
- yield (i, len(str(m))), (i-1, len(str(n)))
- i -= 1
- tmp = n
- yield (i, len(str(m))), (i-1, 0)
- for divisor in range(10 ** (n_divisor - 1), 10 ** n_divisor):
- for dividend in range(10 ** (n_dividend - 1), 10 ** n_dividend):
- if dividend % divisor != remainder:
- continue
- for quotient in range(10 ** (n_quotient - 1), 10 ** n_quotient):
- if dividend // divisor != quotient:
- continue
- if any((step1 != step2) for step1, step2 in zip(steps, gen_steps(dividend, divisor, quotient))):
- continue
- print(dividend, divisor, quotient)
- pass
- if __name__ == '__main__':
- pass
Add Comment
Please, Sign In to add comment