Skip to content

Conversation

@oncsr
Copy link
Contributor

@oncsr oncsr commented Apr 15, 2025

🧷 문제 링크

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분

👀 체감 난이도

✏️ 문제 설명

$1 \le N, K \le 10^9$인 정수 $N, K$가 주어지면, $\gcd(N!, K)$를 구해보자.

🔍 풀이 방법

[사용한 알고리즘]

  • 수학

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}})$에 해결했다.

⏳ 회고

어렵다

@oncsr oncsr added the success 👍 해설을 보지 않고 풀었을 때 label Apr 15, 2025
@ShinHeeEul ShinHeeEul merged commit 53ded45 into main Apr 15, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

success 👍 해설을 보지 않고 풀었을 때

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants