题解 | #素数伴侣#
素数伴侣
https://www.nowcoder.com/practice/b9eae162e02f4f928eac37d7699b352e
import sys,math num1 = int(input().strip()) def just1(a): if a == 1: return False if a == 2: return True for i in range(2,int(math.sqrt(a))+1): if a%i == 0: return False else: return True def solov(a): for j in range(len(list2)): if just1(a+list2[j]) and mind[j] == 0: mind[j] = 1 if re[j] == 0 or solov(re[j]): re[j] = a return True else: return False for line in sys.stdin: a = map(int,line.strip().split(" ")) list1,list2,resault = [],[],0 for i in a: if i%2 == 0: list1.append(i) else: list2.append(i) re = [0]*len(list2) for i in list1: mind = [0]*len(list2) if solov(i): resault +=1 print(resault)