Advertisement
qekaqeka

5966 ПОЛЯКОВ

Mar 31st, 2023
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | Source Code | 0 0
  1. import itertools, math, re
  2. mx = 2023**3
  3.  
  4. def chk3(n):
  5. s3 = ''
  6. while n > 0:
  7. s3 += str(n%3)
  8. n //= 3
  9. p = False
  10. lns3 = len(s3)
  11. for i in range(math.ceil(lns3/2)):
  12. if s3[i] != s3[lns3-i-1]:
  13. p = True
  14. break
  15. return p
  16.  
  17. def sum8(n):
  18. s = 0
  19. while n > 0:
  20. s += n % 8
  21. n //= 8
  22. return s
  23.  
  24. answer = list()
  25.  
  26. for n in range(1, 6):
  27. for s in itertools.product('0123456', repeat = n):
  28. if s[0] == '0':
  29. continue
  30. s = ''.join(s)
  31. t = int(s + s[::-1], 7)
  32. if t > mx:
  33. continue
  34. if chk3(t):
  35. continue
  36. if re.fullmatch(r'\d*2\d*0', str(t)):
  37. answer.append([t, sum8(t)])
  38.  
  39. for n in range(1, 6):
  40. for s in itertools.product('0123456', repeat = n):
  41. if s[0] == '0':
  42. continue
  43. s = ''.join(s)
  44. for k in range(0, 7):
  45.  
  46. t = int(s + str(k) + s[::-1], 7)
  47. if t > mx:
  48. break
  49. if chk3(t):
  50. continue
  51. if re.fullmatch(r'\d*2\d*0', str(t)):
  52. answer.append([t, sum8(t)])
  53.  
  54.  
  55. answer.sort()
  56. for a in answer: print(a)
  57.  
  58.  
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement