azl397985856/leetcode

【每日一题】- 2021-08-11 - 两个质数和

azl397985856 opened this issue · 2 comments

Given an even number (greater than 2), return two prime numbers whose sum will be equal to the given number.

A solution will always exist. See Goldbach’s conjecture.

Example:

Input: 4
Output: 2 + 2 = 4
If there are more than one solution possible, return the lexicographically smaller solution.

If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, then

[a, b] < [c, d]
If a < c OR a==c AND b < d.

even=eval(input("please enter an even number\n"))
prime_list=[]
def isprime(i):
    for j in range(2,i-1):
        if i%j==0:
            return False
    return True
for i in range(2,even-1):
    if isprime(i):
        prime_list.append(i)
for i in prime_list:
    for j in prime_list:
        if i+j==even and i<=j:
            print("%d+%d=%d"%(i,j,even))
stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.