백준 - (# 6588)

https://www.acmicpc.net/problem/6588


Code

import sys

# Get all prime numbers by Eratotenes
max_num = 1000000
total_num_list = [False, False] + [True]*max_num

for i in range(2,len(total_num_list)):
    if total_num_list[i] == True:
        for j in range(i + i, len(total_num_list), i):
            total_num_list[j] = False

# find proper summation
while True:
    n = int(sys.stdin.readline())
    if n == 0:
        break

    result = "Goldbach's conjecture is wrong."
    for i in range(3,n//2+1):
        if total_num_list[i] and total_num_list[n-i]:
            result = '{} = {} + {}'.format(n,i,n-i)
            break

    print(result)

좋은 웹페이지 즐겨찾기