题解 | #查找组成一个偶数最接近的两个素数#
查找组成一个偶数最接近的两个素数
http://www.nowcoder.com/practice/f8538f9ae3f1484fb137789dec6eedb9
提供一个用bisect模块的新思路
list_prime = [2,3]
def isprime(num):
n = 0
if num > 2:
for i in range(2,int(num**0.5)+1):
if num%i == 0 and i != 1:
n = n+1
break
if n == 0:
return 1
else:
return 0
for i in range(4,1000):
if isprime(i):
list_prime.append(i)
import bisect
while 1:
try:
a = int(input())
place = bisect.bisect(list_prime,a//2)
for i in range(1,place+1):
if isprime(a - list_prime[place-i]):
print(list_prime[place-i])
print(a-list_prime[place-i])
break
except:
break