Title Description
Any even number ( Greater than 2) It can be done by 2 It's a prime number , Make up even numbers of 2 There are many kinds of prime numbers , This topic requires the output of the prime pair with the smallest difference between two prime numbers constituting a specified even number .
This question contains several groups of sample input .
Input description :
Enter an even number
Output description :
Output two prime numbers
Example 1
Input
20
Output
7
13
The code implementation is as follows :
def func():
while True:
try:
n = int(input())
nums = []
# find n All prime numbers in
for i in range(n):
times = 0
for j in range(2,i):
if i%j == 0:
times +=1
break
if i >2 and times == 0:
nums.append(i)
mins = []
min1 = n
# Find the difference minimum prime pair
for i in range(len(nums)):
for j in range(i,len(nums)):
min_v = abs(nums[i]-nums[j])
if nums[i]+nums[j] ==n and min1>min_v:
min1 = min_v
mins = [nums[i],nums[j]]
for i in mins:
print(i)
except Exception as e:
#print(e)
break
if __name__ == '__main__':
func()
The Spring Festival at home ,
實現效果:打開App進行自動化測試,只需打開APP一次,按先