Skip to main content

백준 6588 골드바흐의 추측

·80 words·1 min· loading

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

6588번: 골드바흐의 추측각 테스트 케이스에 대해서, n = a + b 형태로 출력한다. 이때, a와 b는 홀수 소수이다. 숫자와 연산자는 공백 하나로 구분되어져 있다. 만약, n을 만들 수 있는 방법이 여러 가지라면, b-a가 가장 큰www.acmicpc.net

간단한문제

  1. 소수를 구한다(체로구현)

  2. n을 1과 n-1부터 시작해서, 각각1 씩 올려가며확인

둘다소수이면 종료

sosu=[False,False]+[True]*int(1000000)for i in range(1,len(sosu)):
    if sosu[i]:        tmp=2        while i*tmp<len(sosu):
            sosu[i*tmp]=False            tmp+=1while True:    t=int(input())
    if t==0:        break    a,b=2,t-2    while a<=b:
        if sosu[a] and sosu[b]:            print(f'{t} = {a} + {b}')
            break        else:            a+=1            b-=1