[20250212] BOJ / G4 / 소수 게임 / 김수연 #97
Merged
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.
🧷 문제 링크
https://www.acmicpc.net/problem/14622
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
두 사람이 번갈아 가면서 소수를 말하는데
-> 상대방이 말한 소수중 3번째로 큰 수만큼 점수 얻음
-> 상대방이 말한 소수 3개 미만이면 상대가 1000점 얻음
-> 해당 소수 말한 팀 -1000점 얻고, 말한 소수로 기록되지 않음
🔍 풀이 방법
**소수인지 여부 **
[에라토스테네스의 체] 사용해서 5000000길이의 prime배열에 소수 여부 저장해둠.
지금까지 등장한 소수인지 여부
5000000길이의 primeExist배열에 등장 여부 저장해둠.
지금까지 상대방이 말한 소수 중 3번째로 큰 수
ArrayList에 저장하되, 오름차순으로 정렬하고, 길이가 3이 넘어가면 바로 index 0 삭제하기
⏳ 회고
에라토스테네스의 체에 대해서 더 공부해야겠다..
그리고 소수여부, 등장한소수여부와 같은거는 그냥 배열 만들어서 저장해두는게 훨씬 빠르다..
(안하면 시간초과....난다....)