Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dec_to_base(N, base):
- if not hasattr(dec_to_base, 'table'):
- dec_to_base.table = '0123456789ABCDEF'
- x, y = divmod(N, base)
- return dec_to_base(x, base) + dec_to_base.table[y] if x else dec_to_base.table[y]
- a, b, p = [int(i) for i in input().split()]
- dec_nums = [dec_to_base(i, p) for i in range(a, b+1)]
- ans = []
- for i in dec_nums:
- temp = list(i)
- #print(temp)
- summ = 0
- for j in temp:
- summ += int(j)**len(temp)
- #print(j)
- #print(summ)
- #print(summ)
- if dec_to_base(summ, p) == int(i):
- ans.append(i)
- print(ans)
- #print(dec_to_base(83, 4))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement