結果

問題 No.1126 SUM
ユーザー realDivineJKrealDivineJK
提出日時 2020-09-25 09:18:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 864 ms / 1,000 ms
コード長 1,279 bytes
コンパイル時間 492 ms
コンパイル使用メモリ 11,028 KB
実行使用メモリ 86,896 KB
最終ジャッジ日時 2023-09-10 14:25:37
合計ジャッジ時間 24,931 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 807 ms
86,820 KB
testcase_01 AC 831 ms
86,676 KB
testcase_02 AC 763 ms
86,680 KB
testcase_03 AC 772 ms
86,832 KB
testcase_04 AC 792 ms
86,728 KB
testcase_05 AC 813 ms
86,764 KB
testcase_06 AC 802 ms
86,628 KB
testcase_07 AC 792 ms
86,704 KB
testcase_08 AC 786 ms
86,828 KB
testcase_09 AC 785 ms
86,788 KB
testcase_10 AC 759 ms
86,632 KB
testcase_11 AC 782 ms
86,696 KB
testcase_12 AC 802 ms
86,760 KB
testcase_13 AC 767 ms
86,708 KB
testcase_14 AC 811 ms
86,896 KB
testcase_15 AC 763 ms
86,672 KB
testcase_16 AC 787 ms
86,784 KB
testcase_17 AC 778 ms
86,760 KB
testcase_18 AC 779 ms
86,848 KB
testcase_19 AC 763 ms
86,888 KB
testcase_20 AC 778 ms
86,668 KB
testcase_21 AC 769 ms
86,676 KB
testcase_22 AC 772 ms
86,628 KB
testcase_23 AC 810 ms
86,716 KB
testcase_24 AC 798 ms
86,764 KB
testcase_25 AC 864 ms
86,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = int(1e9) + 7 # <-- input modulo
maxf = 1000000           # <-- input factional limitation

def make_fact(n, k):
    tmp = n
    perm = [i for i in range(k)]
    L = [0 for _ in range(k)]
    for i in range(k):
        L[i] = tmp % (i + 1)
        tmp //= i + 1
    LL = [0 for _ in range(k)]
    for i in range(k):
        LL[i] = perm[L[-i-1]]
        for j in range(L[-i-1]+1, k):
            perm[j-1] = perm[j]
    return LL

def doubling(n, m, modulo=mod):
    y = 1
    base = n
    tmp = m
    while tmp != 0:
        if tmp % 2 == 1:
            y *= base
            if modulo > 0:
                y %= modulo
        base *= base
        if modulo > 0:
            base %= modulo
        tmp //= 2
    return y

def inved(a, modulo=mod):
    x, y, u, v, k, l = 1, 0, 0, 1, a, modulo
    while l != 0:
        x, y, u, v = u, v, x - u * (k // l), y - v * (k // l)
        k, l = l, k % l
    return x % modulo

fact = [1 for _ in range(maxf+1)]
invf = [1 for _ in range(maxf+1)]

for i in range(maxf):
    fact[i+1] = (fact[i] * (i+1)) % mod
invf[-1] = inved(fact[-1])
for i in range(maxf, 0, -1):
    invf[i-1] = (invf[i] * i) % mod

N, M = map(int, input().split())
S = 0
for i in range(N, M+1):
    S += fact[i] * invf[N] * invf[i-N] % mod
    S %= mod
print(S)
0