def max_prime_num(x,count_2=0):
for i in range(2,int(x**0.5)+1):
if x%i==0:
count_2=1
break
if count_2==1:
return max_prime_num(x-1)
else:
return max_prime_num
//运行以下代码:
import time
t1=time.perf_counter()
print('最大质数是:',max_prime_num(10**15))
t2=time.perf_counter()
print('耗时:',t2-t1)
//返回
最大质数是: 999999999999989
耗时: 3.3144688150000547
网友评论