题解 | #查找组成一个偶数最接近的两个素数#
查找组成一个偶数最接近的两个素数
https://www.nowcoder.com/practice/f8538f9ae3f1484fb137789dec6eedb9
while True: try: n=int(input()) prime_n=[] for i in range(2,n): for j in range(2,int(i**0.5)+1): if i%j==0: break # i能被j整除,则不是素数,跳出j循环,进行下一个i循环 else: # else可以单独与for/while搭配使用 prime_n.append(i) #print(prime_n) diff=[] for each in prime_n: l=[each,n-each,abs(2*each-n)] column=[row[2] for row in diff] if n-each in prime_n and abs(2*each-n) not in column: diff.append(l) #print(diff) diff_num=[row[2] for row in diff] for i in diff: if i[2]==min(diff_num): print(i[0]) print(i[1]) except: break