목차

팩토리얼과 거듭제곱

ps
링크acmicpc.net/…
출처BOJ
문제 번호3964
문제명팩토리얼과 거듭제곱
레벨골드 2
분류

정수론

시간복잡도O(sqrt(m)) + O(T * (sqrt(m)/logm + logn))
인풋사이즈T<=100, n<=10^18, m<=10^12
사용한 언어Python 3.13
제출기록41448KB / 188ms
최고기록72ms
해결날짜2026/03/31

풀이

코드

"""Solution code for "BOJ 3964. 팩토리얼과 거듭제곱".

- Problem link: https://www.acmicpc.net/problem/3964
- Solution link: http://www.teferi.net/ps/problems/boj/3964

Tags: [number theory]
"""

from teflib import io as tio
from teflib import numtheory
from teflib import primenum


@tio.run_n_times
def main():
    primenum.prime_list(10**6)

    n, k = tio.read_ints()
    print(numtheory.exponent_of_num_in_factorial(n, primenum.factorize(k)))


if __name__ == '__main__':
    main()