【问题标题】:Get ceiling of sqrt without float point. Python 3.7.3获取没有浮点数的 sqrt 上限。 Python 3.7.3
【发布时间】: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) 函数。 如果有人可以提供帮助,将不胜感激。

【问题讨论】:

标签: python python-3.x python-3.7 math.sqrt


【解决方案1】:

数学模块有 ceil 和 floor 函数

尝试打印(math.ceil(math.sqrt(NUMBER)))

【讨论】:

  • Int 太大,无法转换为浮点数。再次,sqrt 函数!我需要计算 10**10001 的 sqrt 或 1 后跟 10,001 个零。
  • 然后试试 math.ceil(math.sqrt(10)**10001)。应该解决这个问题
猜你喜欢
  • 2012-08-27
  • 1970-01-01
  • 1970-01-01
  • 2013-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-18
相关资源
最近更新 更多