結果

問題 No.129 お年玉(2)
ユーザー nebukuro09nebukuro09
提出日時 2016-09-08 11:24:16
言語 Python2
(2.7.18)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 782 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 6,532 KB
実行使用メモリ 6,692 KB
最終ジャッジ日時 2023-08-18 17:43:08
合計ジャッジ時間 2,563 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,156 KB
testcase_01 AC 12 ms
6,260 KB
testcase_02 AC 12 ms
6,008 KB
testcase_03 AC 11 ms
6,108 KB
testcase_04 AC 11 ms
6,064 KB
testcase_05 AC 12 ms
6,244 KB
testcase_06 AC 18 ms
6,360 KB
testcase_07 AC 18 ms
6,448 KB
testcase_08 AC 12 ms
6,112 KB
testcase_09 AC 17 ms
6,360 KB
testcase_10 AC 17 ms
6,340 KB
testcase_11 AC 17 ms
6,328 KB
testcase_12 AC 12 ms
6,088 KB
testcase_13 AC 11 ms
6,012 KB
testcase_14 AC 17 ms
6,432 KB
testcase_15 AC 17 ms
6,392 KB
testcase_16 AC 19 ms
6,688 KB
testcase_17 AC 16 ms
6,256 KB
testcase_18 AC 16 ms
6,340 KB
testcase_19 AC 13 ms
6,080 KB
testcase_20 AC 19 ms
6,488 KB
testcase_21 AC 16 ms
6,344 KB
testcase_22 AC 16 ms
6,292 KB
testcase_23 AC 16 ms
6,592 KB
testcase_24 AC 11 ms
6,104 KB
testcase_25 AC 17 ms
6,516 KB
testcase_26 AC 14 ms
6,260 KB
testcase_27 AC 15 ms
6,372 KB
testcase_28 AC 20 ms
6,692 KB
testcase_29 AC 11 ms
5,976 KB
testcase_30 AC 10 ms
6,220 KB
testcase_31 AC 10 ms
6,060 KB
testcase_32 AC 11 ms
6,108 KB
testcase_33 AC 10 ms
6,116 KB
testcase_34 AC 11 ms
6,076 KB
testcase_35 AC 11 ms
6,060 KB
testcase_36 AC 11 ms
6,160 KB
testcase_37 AC 11 ms
5,992 KB
testcase_38 AC 14 ms
6,240 KB
testcase_39 AC 13 ms
6,172 KB
testcase_40 AC 15 ms
6,352 KB
testcase_41 AC 14 ms
6,448 KB
testcase_42 AC 13 ms
6,124 KB
testcase_43 AC 12 ms
6,020 KB
testcase_44 AC 13 ms
6,112 KB
testcase_45 AC 12 ms
6,072 KB
testcase_46 AC 12 ms
6,140 KB
testcase_47 AC 15 ms
6,252 KB
testcase_48 AC 12 ms
6,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10**9
def ncr(n, r):
    if n - r < r:
        r = n-r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [0 for i in range(r)]
    denominator = [0 for i in range(r)]

    for k in range(r):
        numerator[k] = n - r + k + 1
        denominator[k] = k + 1
    
    for p in range(2, r+1):
        pivot = denominator[p-1]
        if pivot > 1:
            offset = (n-r) % p
        for k in range(p-1, r, p):
            numerator[k-offset] /= pivot
            denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result = (result*numerator[k]) % MOD

    return result
N,M = input(), input()
N -= N/(M*1000)*M*1000
N /= 1000
if N >= M:
    print pow(2, M) % MOD
else:
    print ncr(M, N)
0