結果

問題 No.420 mod2漸化式
ユーザー nebukuro09nebukuro09
提出日時 2016-09-20 11:23:47
言語 Python2
(2.7.18)
結果
AC  
実行時間 11 ms / 1,000 ms
コード長 794 bytes
コンパイル時間 914 ms
コンパイル使用メモリ 6,792 KB
実行使用メモリ 6,216 KB
最終ジャッジ日時 2023-08-26 00:40:51
合計ジャッジ時間 2,543 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,040 KB
testcase_01 AC 9 ms
5,980 KB
testcase_02 AC 9 ms
5,988 KB
testcase_03 AC 9 ms
5,972 KB
testcase_04 AC 9 ms
5,916 KB
testcase_05 AC 9 ms
6,148 KB
testcase_06 AC 9 ms
6,004 KB
testcase_07 AC 9 ms
5,988 KB
testcase_08 AC 10 ms
6,212 KB
testcase_09 AC 10 ms
6,056 KB
testcase_10 AC 10 ms
6,004 KB
testcase_11 AC 10 ms
5,976 KB
testcase_12 AC 10 ms
6,048 KB
testcase_13 AC 10 ms
6,092 KB
testcase_14 AC 10 ms
5,924 KB
testcase_15 AC 10 ms
6,060 KB
testcase_16 AC 10 ms
6,144 KB
testcase_17 AC 10 ms
6,052 KB
testcase_18 AC 9 ms
6,160 KB
testcase_19 AC 10 ms
5,984 KB
testcase_20 AC 11 ms
6,216 KB
testcase_21 AC 10 ms
6,092 KB
testcase_22 AC 10 ms
6,004 KB
testcase_23 AC 9 ms
6,012 KB
testcase_24 AC 9 ms
6,148 KB
testcase_25 AC 10 ms
6,008 KB
testcase_26 AC 11 ms
5,988 KB
testcase_27 AC 11 ms
6,056 KB
testcase_28 AC 10 ms
6,044 KB
testcase_29 AC 10 ms
6,212 KB
testcase_30 AC 10 ms
6,004 KB
testcase_31 AC 10 ms
6,004 KB
testcase_32 AC 10 ms
6,008 KB
testcase_33 AC 10 ms
6,056 KB
testcase_34 AC 10 ms
5,984 KB
testcase_35 AC 10 ms
6,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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])

    return result

x = input()
if x == 0:
    print 1, 0
elif x >= 32:
    print 0, 0
else:
    y = ncr(30, x-1)
    print ncr(31, x), sum(2**i*y for i in xrange(31))
0