๋ฌธ์
https://www.acmicpc.net/problem/6588
ํ์ด
# ๋ฐฑ์ค 6588๋ฒ ๋ฌธ์ - ๊ณจ๋๋ฐํ์ ์ถ์ธก
import sys
input = sys.stdin.readline
n = 1000001
# ์์ ์๋ ๋ชจ๋ ํ์ ์ฒ๋ฆฌ
prime = [1] * n
for i in range(3, int(n ** 0.5) + 1, 2):
if prime[i]:
for j in range(i * 2, n, i):
prime[j] = 0
# k๊ฐ ๋ง๋ค์ด์ง๋ ๋ ํ์์ธ ์์ ๊ฒ์
while 1:
k = int(input())
if not k:
break
for i in range(3, int(k // 2) + 1, 2):
if prime[i] and prime[k - i]:
print(f"{k} = {i} + {k - i}")
break
else:
print("Goldbach's conjecture is wrong.")
์๋ผํ ์คํ ๋ค์ค์ ์ฒด๋ฅผ ๊ตฌํํ ์ ์๋ค๋ฉด ๊ฐ๋จํ ํ ์ ์๋ ๋ฌธ์ ์๋ค.
'๐๏ธ Algorithm > ๐ฉ ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 1916๋ฒ_์ต์๋น์ฉ ๊ตฌํ๊ธฐ (0) | 2023.04.27 |
---|---|
๐ฉ [๋ฐฑ์ค] [Python] [Gold5] 5582๋ฒ_๊ณตํต ๋ถ๋ถ ๋ฌธ์์ด (0) | 2023.04.26 |
๐ฉ [๋ฐฑ์ค] [Python] [Gold1] 2042๋ฒ_๊ตฌ๊ฐ ํฉ ๊ตฌํ๊ธฐ (0) | 2023.04.24 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver3] 11478๋ฒ_์๋ก ๋ค๋ฅธ ๋ถ๋ถ ๋ฌธ์์ด์ ๊ฐ์ (0) | 2023.04.23 |
๐ฉ [๋ฐฑ์ค] [Python] [Silver3] 2512๋ฒ_์์ฐ (0) | 2023.04.22 |