fork download
  1. import sys
  2. import codecs
  3. sys.stdout = codecs.getwriter('utf8')(sys.stdout)
  4. n = int(raw_input())
  5. ng, n = (True, -n) if n < 0 else (False, n)
  6. if n < 4:
  7. raise ValueError
  8. def bn(n,b):
  9. return ('' if n//b == 0 else bn(n//b,b)) + chr(n%b + (48 if n%b <= 9 else 87))
  10. def c4(n,b):
  11. return (1 if n%b==4 else 0) + (0 if n//b == 0 else c4(n//b,b)[0]),b
  12. b = sorted([c4(n,b) for b in range(4,37)], lambda x,y: cmp(y[0],x[0]))[0][1]
  13. print ('-' if ng else '') + bn(n,b) + ''.join([unichr(ord(c)+8272) for c in str(b)])
Success #stdin #stdout 0.01s 7856KB
stdin
624
stdout
4444₅