Advertisement
Guest User

123

a guest
Apr 23rd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. def dec_to_base(N, base):
  2. if not hasattr(dec_to_base, 'table'):
  3. dec_to_base.table = '0123456789ABCDEF'
  4. x, y = divmod(N, base)
  5. return dec_to_base(x, base) + dec_to_base.table[y] if x else dec_to_base.table[y]
  6.  
  7.  
  8. a, b, p = [int(i) for i in input().split()]
  9.  
  10. dec_nums = [dec_to_base(i, p) for i in range(a, b+1)]
  11. ans = []
  12.  
  13. for i in dec_nums:
  14. temp = list(i)
  15. #print(temp)
  16. summ = 0
  17. for j in temp:
  18. summ += int(j)**len(temp)
  19. #print(j)
  20. #print(summ)
  21. #print(summ)
  22. if dec_to_base(summ, p) == int(i):
  23. ans.append(i)
  24. print(ans)
  25. #print(dec_to_base(83, 4))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement