fork download
  1. # your code goes here
  2. import string
  3. import math
  4.  
  5. DIGITS = string.ascii_letters
  6. def to26base(num: int) -> str:
  7. ret = ""
  8. while num:
  9. ret += DIGITS[num%26]
  10. num //= 26
  11. return ret[::-1] or DIGITS[0]
  12.  
  13. def format_big_num(num: int) -> str:
  14. exp = int(math.log10(num))
  15. adjusted_exp = exp // 3 - 1
  16. if adjusted_exp < 0:
  17. return str(num)
  18. base26exp = to26base(adjusted_exp)
  19. rem = num // 10**((adjusted_exp + 1) * 3)
  20. return str(rem) + base26exp
  21.  
  22. for x in [1, 10, 100, 1000, 2000, 5000, 100000, 2**64, 2**128, 2**256, 2**1024]:
  23. print(format_big_num(x))
  24.  
Success #stdin #stdout 0.03s 9916KB
stdin
Standard input is empty
stdout
1
10
100
1a
2a
5a
100a
18f
340l
115y
179dx