boris-vlasenko

P,Q, n

Nov 26th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.36 KB | None | 0 0
  1. def TenToP(n,p):
  2.     res = ''
  3.     while n >= p:
  4.         res = str(n % p) + res
  5.         n = n // p
  6.     res = str(n) + res
  7.     return res
  8.  
  9. def ToTen(n,p):
  10.     res = 0
  11.     i = 0
  12.     while n:
  13.             res += (n % 10) * p**i
  14.             i += 1
  15.             n = n // 10
  16.     return res
  17.    
  18. q = int(input())
  19. p = int(input())
  20. n = int(input())   
  21. print(TenToP(ToTen(n,p),q))
  22. n = int(input())   
  23. print(TenToP(ToTen(n,q),p))
Advertisement
Add Comment
Please, Sign In to add comment