【发布时间】:2020-10-31 00:26:47
【问题描述】:
我需要求平方根的上限,例如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) 函数。
如果有人可以提供帮助,将不胜感激。
【问题讨论】:
-
那是 1 和 10,000 个零。为什么需要这么大的数字?
-
我需要计算非常大的数字,看看它们是否是素数。
-
这似乎是 stackoverflow.com/questions/28150824/… 的副本。试试
import decimalprint(int(decimal.Decimal(10**10001).sqrt())+1) -
问题是
print(int(sqrt(10*10001))+1),它非常可计算并打印317。是错字吗?
标签: python python-3.x python-3.7 math.sqrt