获得无浮点数的sqrt天花板。Python 3.7.3

2024-04-26 23:14:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要得到平方根的上限,比如10**10001(10^10001)。如果我这样做:

from math import sqrt
print(int(sqrt(10**10001))+1)

我看,它给了我一个OverflowError。 更准确地说,一个

Traceback (most recent call last)
  File <stdin>, line 1, in <module>
OverflowError: int too large to convert to float.

我需要一个整数作为答案。OverflowError来自math.sqrt(x)函数。 如果有人能帮忙,我们将不胜感激


Tags: tofromimportmoststdinmathsqrtcall