Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import itertools, math, re
- mx = 2023**3
- def chk3(n):
- s3 = ''
- while n > 0:
- s3 += str(n%3)
- n //= 3
- p = False
- lns3 = len(s3)
- for i in range(math.ceil(lns3/2)):
- if s3[i] != s3[lns3-i-1]:
- p = True
- break
- return p
- def sum8(n):
- s = 0
- while n > 0:
- s += n % 8
- n //= 8
- return s
- answer = list()
- for n in range(1, 6):
- for s in itertools.product('0123456', repeat = n):
- if s[0] == '0':
- continue
- s = ''.join(s)
- t = int(s + s[::-1], 7)
- if t > mx:
- continue
- if chk3(t):
- continue
- if re.fullmatch(r'\d*2\d*0', str(t)):
- answer.append([t, sum8(t)])
- for n in range(1, 6):
- for s in itertools.product('0123456', repeat = n):
- if s[0] == '0':
- continue
- s = ''.join(s)
- for k in range(0, 7):
- t = int(s + str(k) + s[::-1], 7)
- if t > mx:
- break
- if chk3(t):
- continue
- if re.fullmatch(r'\d*2\d*0', str(t)):
- answer.append([t, sum8(t)])
- answer.sort()
- for a in answer: print(a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement