[20250415] SWEA / D4 / 팩토리얼과 최대공약수 / 권혁준 #309
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://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWnghFyq9eMDFAQU&categoryId=AWnghFyq9eMDFAQU&categoryType=CODE&problemTitle=7466&orderBy=FIRST_REG_DATETIME&selectCodeLang=ALL&select-1=&pageSize=10&pageIndex=1
🧭 풀이 시간
15분
👀 체감 난이도
✏️ 문제 설명
🔍 풀이 방법
[사용한 알고리즘]
gcd를 구한다는 것은 다시 말하면 두 수를 소인수분해 했을 때 최대한 많이 겹치는 소인수들을 골라 곱해주는 것이다.
$K$ 를 소인수분해한 결과를 ${p_1}^{k_1} \times {p_2}^{k_2} \times \cdots$ 라고 하면, $N!$ 에 소수 $p_1, p_2, \cdots$ 들이 각각 몇 개 곱해졌는지 구해서 정답을 알 수 있다.
그리고$N!$ 에 곱해진 소수 $p$ 의 개수는 $\lfloor \dfrac{N}{p} \rfloor + \lfloor \dfrac{N}{p^2} \rfloor + \lfloor \dfrac{N}{p^3} \rfloor + \cdots$ 이다.
시간복잡도$O(\sqrt{K} \log_{2}{\sqrt{K}})$ 에 해결했다.
⏳ 회고
어렵다