本帖最后由 huomqh 于 2016-7-12 15:00 编辑 def isPrime(x):
i=2
if x<=1:
return 0
while i**2<=x:
if x%i==0:
return 0
i+=1
return 1
def f(x,y,z):
return x*x+y*x+z
def g(x,y):
if x<0:
return x*x-4*y
else:
return -1
import time
tt=time.time()
b=3
count=0
counta=0
countb=0
while b<=999:
if isPrime(b)==0:
b+=2
continue
a=999
while (a>=-999) and (g(a,b)<0):
i=1
while isPrime(f(i,a,b))==1:
i+=1
if i-1>count:
count,counta,countb=i-1,a,b
a-=2
b+=2
print('a=%d,b=%d,a*b=%d,n=%d'%(counta,countb,counta*countb,count))
print('用时:%.4f s'%(time.time() - tt))
结果:a=-61,b=971,a*b=-59231,n=70
用时:1.3211 s
|