sd44

Untitled

Nov 5th, 2023
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. import itertools
  2.  
  3. # 可知y =1 ,而乘数后八位为range(2,10)的全排列。
  4. # 至此,已经找出乘式中所有元素。
  5.  
  6. # first_pair为乘数每一位数 和其与easy相乘的首位数在全排列中的索引对儿元组
  7. first_pair = [(0, 6), (1, 4), (2, 5), (4, 7), (5, 0), (6, 3), (7, 2)]
  8.  
  9. for i in itertools.permutations(range(2, 10)):
  10.     easy = 1 + i[7] * 10 + i[3] * 100 + i[1] * 1000
  11.     math_tuple = i[2:5] + i
  12.     math_str = ''.join(map(str, math_tuple))
  13.     maths = int(math_str)
  14.  
  15.     x = easy * maths
  16.  
  17.     if int(i[3] * easy / 10000) != 1:
  18.         continue
  19.  
  20.     right = True
  21.     for j in first_pair:
  22.         if int(i[j[0]] * easy / 10000) != i[j[1]]:
  23.             right = False
  24.             continue
  25.  
  26.     if not right:
  27.         continue
  28.  
  29.     if int(easy * maths / (10**14)) != i[5]:
  30.         continue
  31.  
  32.     print(easy, " * ", maths)
  33.  
Advertisement
Add Comment
Please, Sign In to add comment