結果

問題 No.554 recurrence formula
ユーザー roarisroaris
提出日時 2019-08-18 20:45:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 417 bytes
コンパイル時間 480 ms
コンパイル使用メモリ 82,228 KB
実行使用メモリ 60,208 KB
最終ジャッジ日時 2024-04-09 02:43:54
合計ジャッジ時間 1,796 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
52,488 KB
testcase_01 AC 36 ms
52,204 KB
testcase_02 AC 35 ms
52,596 KB
testcase_03 AC 35 ms
53,500 KB
testcase_04 AC 35 ms
52,712 KB
testcase_05 AC 34 ms
51,936 KB
testcase_06 AC 35 ms
52,032 KB
testcase_07 AC 35 ms
52,552 KB
testcase_08 AC 35 ms
51,828 KB
testcase_09 AC 35 ms
53,336 KB
testcase_10 AC 39 ms
58,564 KB
testcase_11 AC 39 ms
58,512 KB
testcase_12 AC 39 ms
59,984 KB
testcase_13 AC 40 ms
59,152 KB
testcase_14 AC 39 ms
58,616 KB
testcase_15 AC 39 ms
58,164 KB
testcase_16 AC 39 ms
59,460 KB
testcase_17 AC 40 ms
60,208 KB
testcase_18 AC 38 ms
58,912 KB
testcase_19 AC 41 ms
58,436 KB
testcase_20 AC 40 ms
58,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())

if n == 1:
    print(1)
    exit()
    
MOD = 10 ** 9 + 7
even_acc, odd_acc = 0, 1

for i in range(2, n+1):
    if i == n:
        if i % 2 == 0:
            print(i * odd_acc % MOD)
        else:
            print(i * even_acc % MOD)
        exit()
        
    if i % 2 == 0:
        even_acc += i * odd_acc
        even_acc %= MOD
    else:
        odd_acc += i * even_acc
        odd_acc %= MOD
0