Pandaaaa906

Untitled

Jun 17th, 2022 (edited)
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. from itertools import zip_longest
  2.  
  3. remainder = 5
  4. n_dividend = 4  # 被除数
  5. n_divisor = 1  # 除数
  6. n_quotient = 3  # 商
  7.  
  8. steps = (
  9.     # q_offset q, e_offset e
  10.     ((2, 1), (1, 2)),
  11.     ((1, 1), (0, 2)),
  12.     ((0, 1), (-1, 0)),
  13. )
  14.  
  15.  
  16. def gen_steps(e, s, q):
  17.     n_dividend = len(str(e))
  18.     n_quotient = len(str(q))
  19.     i = n_quotient - 1
  20.     tmp = int(str(e)[:n_dividend-n_quotient+1])
  21.     while i > 0:
  22.         m = int(str(q)[n_quotient - i - 1]) * s
  23.         n = int(str(tmp - m) + str(e)[n_dividend - i-1])
  24.         yield (i, len(str(m))), (i-1, len(str(n)))
  25.         i -= 1
  26.         tmp = n
  27.     yield (i, len(str(m))), (i-1, 0)
  28.  
  29.  
  30. for divisor in range(10 ** (n_divisor - 1), 10 ** n_divisor):
  31.     for dividend in range(10 ** (n_dividend - 1), 10 ** n_dividend):
  32.         if dividend % divisor != remainder:
  33.             continue
  34.         for quotient in range(10 ** (n_quotient - 1), 10 ** n_quotient):
  35.             if dividend // divisor != quotient:
  36.                 continue
  37.             if any((step1 != step2) for step1, step2 in zip(steps, gen_steps(dividend, divisor, quotient))):
  38.                 continue
  39.             print(dividend, divisor, quotient)
  40.  
  41.             pass
  42.  
  43. if __name__ == '__main__':
  44.     pass
  45.  
Add Comment
Please, Sign In to add comment