Merged
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.
🧷 문제 링크
https://www.acmicpc.net/problem/27470
🧭 풀이 시간
20분
👀 체감 난이도
✏️ 문제 설명
멋진 집합이란, 모든 원소들의 최대공약수가 1보다 큰 정수들의 집합이다.
크기가 N인 중복집합이 주어지면, 크기가 N/2이상인 멋진 집합을 찾아보자.
🔍 풀이 방법
일단, 멋진 집합이 존재한다고 가정하고 들어간다.
아무 수나 하나 뽑았을 때, 이 수가 멋진 집합에 포함될 확률은 1/2이상이다.
그러면, 이 수를 소인수분해해서 나오는 소인수들로 멋진 집합이 존재하는지 전체 배열을 한 번씩 테스트한다.
-> A의 소인수의 개수가 logA보다 작으므로 시간복잡도는 O(NlogA)이다.
만약 멋진 집합이 진짜 존재한다면, 바로 출력하고 return한다.
아니라면 다시 아무 수나 하나 뽑아서 똑같이 수행한다.
위 과정을 대략 x번 했을 때까지 멋진 집합이 나오지 않았다면?
처음에 멋진 집합이 존재한다고 가정했기 때문에, 이럴 확률은 (1/2)^x보다 작다.
50번 했다고 치면, 약 0.0000000000000008%정도이다.
-> 이건 걍 멋진 집합이 없다는 뜻으로 받아들인다.
⏳ 회고
ez