[20250312] BOJ / P4 / 이항 계수 5 / 권혁준 #236
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/11439
🧭 풀이 시간
10분
👀 체감 난이도
✏️ 문제 설명
이항 계수$comb(n, k)$ 를 $m$ 으로 나눈 나머지를 구해보자.
🔍 풀이 방법
[사용한 알고리즘]
만약, 어떤 수
정확히는, 소인수분해라기 보다는, 정수 배열 cnt를 정의해서$cnt[i] = \dfrac{x}{i} + \dfrac{x}{i\times i} + \dfrac{x}{i \times i \times i} + \cdots $ 이다. (분수 계산에서 나머지는 버린다.)
cnt[i] = 소인수 i가 x!에서 곱해진 횟수를 구할 것이다.이 때, 소수 i에 대해
이제, n!을 소인수분해한 결과를 cnt에 더해주고, k!과 (n-k)!을 소인수분해한 결과를 각각 cnt에서 빼주면 최종 소인수분해 결과가 나오게 된다.
이 배열을 순회하며 분할 정복을 이용한 거듭제곱으로 빠르게 결과값을 구해주면 된다.
⏳ 회고
어제 풀었던 문제랑 같은 테크닉을 쓴다. (조합의 소인수분해 결과 구하기)
https://www.acmicpc.net/problem/1095