AtCoder-Library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub ryusuke920/AtCoder-Library

:warning: Math/nCk.py

Code

def calc_facinv(n: int) -> list:
    '逆元テーブルを作成する'

    # 階乗テーブルの作成
    fac = [0] * (n + 1)
    fac[0] = 1
    for i in range(1, n + 1):
        fac[i] = fac[i - 1] * i
        fac[i] %= mod
    
    # 逆元テーブルの作成
    fac_inv = [0] * (n + 1)
    fac_inv[0] = 1
    for i in range(1, n + 1):
        fac_inv[i] = pow(fac[i], mod - 2, mod)
    
    return fac, fac_inv

def combination(n: int, k: int) -> int:
    '''nCkを計算する'''

    return fac[n] * fac_inv[k] * fac_inv[n - k] % mod

def main() -> None:

    n, k = map(int, input().split())

    mod = 10 ** 9 + 7
    fac, fac_inv = calc_facinv(n)

    ans = combination(n, k)
    print(ans)


if __name__ == "__main__":
    main()
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/onlinejudge_verify/documentation/build.py", line 71, in _render_source_code_stat
    bundled_code = language.bundle(stat.path, basedir=basedir, options={'include_paths': [basedir]}).decode()
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.12.5/x64/lib/python3.12/site-packages/onlinejudge_verify/languages/python.py", line 96, in bundle
    raise NotImplementedError
NotImplementedError
Back to top page