小编phd*_*upA的帖子

使用Python 3快速计算实数巨大整数的基数3值

我们有很多像(10**1500000)+1,并希望将其转换为基数3.下面是我们用普通Python发现的最快方式运行代码(不使用numpy或CAS库).

如何加速基础转换(到基数3)的性能?

我们想知道如何通过以下两种方式完成此操作:

  1. 仅使用Python 3的内置函数(没有numpy)?
  2. 在普通的Python 3程序中使用numpy(或另一个CAS库)?

非常欢迎任何帮助.这是我们目前的代码:

#### --- 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 …
Run Code Online (Sandbox Code Playgroud)

python math performance

5
推荐指数
1
解决办法
156
查看次数

标签 统计

math ×1

performance ×1

python ×1