[PGS] 소수 만들기 - #78
Open
been12151 wants to merge 15 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🍪 문제 이름
Resolve: 소수 만들기
🍊 문제 정의
inputnums: 정수가 담긴 배열 (3 ≤ 길이 ≤ 50, 각 원소 1 이상 1,000 이하)outputnums에서 3개의 수를 뽑아 더했을 때 소수가 되는 경우의 수예시
🍑 알고리즘 설계
combinations로 3개씩 뽑는 모든 조합을 생성하고, 각 조합의 합이 소수인지 판별하는is_prime()을 내부 함수로 정의해 체크.is_prime()은 2부터 √n까지만 나눠보는 방식으로 불필요한 반복을 줄임. 소수인 경우answer를 1 증가.🥝 최악 수행 시간 복잡도
O(n³ × √m)(n = nums 길이, m = 세 수의 합 최댓값)🍰 특이 사항 (Optional)
is_prime()을 2부터 √n까지만 확인하는 방식으로 구현해 완전탐색(2 ~ n-1)보다 효율적으로 처리함.