我们有很多像(10**1500000)+1,并希望将其转换为基数3.下面是我们用普通Python发现的最快方式运行代码(不使用numpy或CAS库).
如何加速基础转换(到基数3)的性能?
我们想知道如何通过以下两种方式完成此操作:
非常欢迎任何帮助.这是我们目前的代码:
#### --- Convert a huge integer to base 3 --- ####
# Convert decimal number n to a sequence of list elements
# with integer values in the range 0 to base-1.
# With divmod, it's ca. 1/3 faster than using n%b and then n//=b.
def numberToBase(n, b):
    digits = []
    while n:
        n, rem = divmod(n, b)
        digits.append(rem)
    return digits[::-1]
# Step 2: Convert given integer to another base
# With …