結果

問題 No.3048 Swing
ユーザー gew1fw
提出日時 2025-06-12 15:37:34
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 868 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 82,720 KB
実行使用メモリ 67,660 KB
最終ジャッジ日時 2025-06-12 15:38:20
合計ジャッジ時間 5,173 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other RE * 59
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10**9 + 7

def comb_mod(a, b, p):
    if b < 0 or b > a:
        return 0
    # Lucas theorem
    def fact_mod(n, p):
        if n == 0:
            return 1
        res = 1
        for i in range(1, n+1):
            res = (res * i) % p
        return res

    res = 1
    while a > 0 or b > 0:
        ai = a % p
        bi = b % p
        if bi > ai:
            return 0
        # Compute C(ai, bi) mod p
        numerator = 1
        for i in range(bi+1, ai+1):
            numerator = (numerator * i) % p
        denominator = 1
        for i in range(1, ai - bi + 1):
            denominator = (denominator * i) % p
        den_inv = pow(denominator, p-2, p)
        res = (res * numerator * den_inv) % p
        a = a // p
        b = b // p
    return res

K = int(input())
if K % 2 != 0:
    print(0)
else:
    n = K // 2
    print(comb_mod(K, n, MOD))
0