-
[Python] 백준 - 9020 골드바흐의 추측__Python/__Algorithm 2022. 1. 7. 16:42
# 실버 1
[문제]
링크 : https://www.acmicpc.net/problem/9020
문제 풀이
- 소수 판별
- 두 소수의 합계이며 값의 차이가 최소 > N값의 절반부터 반복문을 실행 > i, N-i가 모두 소수일 경우 출력
- 정답 풀이 후 다른 풀이 방식이나 코드 축소를 참고하고자 숏코딩을 보는 편인데, 이 문제는 다른 사람의 풀이(숏코딩) 이해 어려움.
구현 코드
import math import sys def sosu(n): for i in range(2,int(math.sqrt(n))+1): if n%i == 0: return False return True for _ in range(int(sys.stdin.readline())): N = int(sys.stdin.readline()) for i in range(N//2,1,-1): if sosu(i) & sosu(N-i): print(i,N-i) break
실행 결과
728x90'__Python > __Algorithm' 카테고리의 다른 글
[Python] 백준 - 1927 최소 힙 (0) 2022.01.07 [Python] 백준 - 2667 단지번호 붙이기 (0) 2022.01.07 [Python] 백준 - 2178 미로 탐색 (0) 2022.01.07 [Python] 백준 - 1904 01타일 (0) 2021.12.21 [Python] 백준 - 9184 신나는 함수 실행 (0) 2021.12.21