关于如何解决这个不等式的任何见解:n!<=10^6?

2024-10-03 15:30:29 发布

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

我一直在和n打交道<;=10^6在python中使用symphy.solver。例如,下面是我的代码:

import sympy as sy

print(sy.solve_univariate_inequality(sy.factorial(n) <= 10**6,n))

我试过解单变量不等式和求解方法,但都不管用。错误为“raise NOTEImplementedError('解算集无法解此方程')”

我很好奇是否有其他方法来处理这种不平等。有什么见解吗


Tags: 方法代码importltas错误printsolver
3条回答

如果你纯粹从数学的角度来处理这个问题,你可以增加n来得到超过阈值的阶乘

results=[]
n=0
n_factorial=1
while n_factorial<=10**6:
    results.append(n)
    print(n,n_factorial)
    n+=1    
    n_factorial*=n
    
print(results)

输出: 0 1 1 1 2 2 3 6 4 24 5 120 6 720 7 5040 8 40320 9 362880 [0,1,2,3,4,5,6,7,8,9]

docs

Currently supported:
  polynomial

  transcendental

  piecewise combinations of the above

  systems of linear and polynomial equations

  systems containing relational expressions

看起来不支持阶乘

i = 1
factorial = 1
while factorial <= 1_000_000:
    factorial  *= i
    i += 1

print(f"equation valid for n in [1-{i-2}]")

相关问题 更多 >