We have a large number like (10**1500000)+1, and want to convert it to base 3. Below is running code with the fastest way we found with normal Python (without using numpy o
Here's a method that expands on your convsteps
solution by recursing with the base squaring with each call. Some extra work is required to remove leading zeros.
def number_to_base(n, b):
if n < b:
return [n]
else:
digits = [d for x in number_to_base(n, b*b) for d in divmod(x, b)]
return digits if digits[0] else digits[1:]
My quick timing test shows that it's the same as your step2
within the margin of error. But it's simpler and probably has fewer bugs.