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/9359
🧭 풀이 시간
15분
👀 체감 난이도
✏️ 문제 설명
A이상 B이하의 수 중에서 N과 서로소인 수의 개수를 구해보자.
🔍 풀이 방법
문제를 살짝 바꿔서, 1이상 x이하인 수 중에서 N과 서로소인 수의 개수를 구해보자.
이를 f(x)라고 정의한다.
어떤 수가 N과 서로소라는 것은, 두 수를 소인수분해했을 때 공통 소인수가 없다는 뜻이다.
그래서 반대로 생각하면, f(x)를 구할 때 (전체 개수) - (N과 서로소가 아닌 수의 개수) 처럼 구해줬다.
N과 서로소가 아닌 수의 개수는 N을 소인수분해한 뒤에 그 결과에 포함된 소수들로 포함 배제의 원리를 이용해 구할 수 있다. 결과 소수의 개수가$O(\log{N})$ 이라 시간 내에 돌아간다.
⏳ 회고
재밌따