相关疑难解决方法(0)

OverflowError Python int太大而无法转换为C long

#!/usr/bin/python
import sys,math
n = input("enter a number to find the factors   :   ")
j,flag,b= 0l,False,0l
for b in xrange(1,n+1):
    a = n + (b*b)
    j = long(math.sqrt(a))
    if a == j*j:
        flag = True
        break
if flag:
    c = j+b
    d = j-b
    print "the first factor is   :   ",c ,"  and the second factor is   :   ",d
Run Code Online (Sandbox Code Playgroud)

当我运行此代码时,它会为不同的输入抛出不同类型的错误.

以下是一种输入

linux@terminal:~$ ./fermat.py
enter a number to find the factors   :   544564564545456
Traceback (most recent call last):
  File "./fermat.py", line …
Run Code Online (Sandbox Code Playgroud)

python python-2.7

22
推荐指数
1
解决办法
3万
查看次数

标签 统计

python ×1

python-2.7 ×1