목차

이항 계수 4

ps
링크acmicpc.net/…
출처BOJ
문제 번호11402
문제명이항 계수 4
레벨플래티넘 5
분류

수학, 정수론

시간복잡도O(m + logn/logm)
인풋사이즈n<=10^18, m<=2000
사용한 언어Python
제출기록28776KB / 64ms
최고기록56ms
해결날짜2021/01/20

풀이

코드

from teflib import combinatorics


def main():
    N, K, M = [int(x) for x in input().split()]
    comb_table = combinatorics.CombTable(M - 1, M)
    answer = 1
    while N > 0:
        N, n_mod = divmod(N, M)
        K, k_mod = divmod(K, M)
        answer *= comb_table.get(n_mod, k_mod)

    print(answer % M)


if __name__ == '__main__':
    main()