fork download
  1. # http://c...content-available-to-author-only...e.com/questions/54105/all-your-bijective-base-are-belong-to-us
  2.  
  3. #M="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz<=>"
  4. #M="0123456789"+"".join(map(chr,range(65,91)+range(97,123)))+"<=>"
  5. #u="".join(map(chr,range(65,91)));M="0123456789"+u+u.lower()+"<=>"
  6. #M="".join(map(chr,range(48,58)+range(65,91)+range(97,123)))+"<=>"
  7.  
  8. R=range;M="".join(map(chr,R(48,58)+R(65,91)+R(97,123)))+"<=>"
  9. b,s,o=input()
  10. F=M.find
  11. e=F(o)<2
  12. B=lambda n:n and B(n/F(o)-e)+M[n%F(o)+e]or""
  13. n=B(sum(F(s[~j])*F(b)**j for j in R(len(s))))
  14. i=n.find('0')
  15. n=list(n)
  16. while-~i:n=n[:i-1]+[M[F(n[i-1])-1]]+[o]+n[i+1:];n=n["0"==n[0]:];i="".join(n).find('0')
  17. print"".join(n)
Success #stdin #stdout 0.01s 9016KB
stdin
"3","31","1"
stdout
1111111111