結果

問題 No.978 Fibonacci Convolution Easy
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-01-31 22:57:03
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 363 bytes
コンパイル時間 495 ms
コンパイル使用メモリ 81,852 KB
実行使用メモリ 59,780 KB
最終ジャッジ日時 2023-10-19 01:06:16
合計ジャッジ時間 2,141 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
59,780 KB
testcase_01 AC 51 ms
59,780 KB
testcase_02 AC 47 ms
59,780 KB
testcase_03 AC 64 ms
59,780 KB
testcase_04 AC 48 ms
59,780 KB
testcase_05 AC 44 ms
59,780 KB
testcase_06 AC 51 ms
59,780 KB
testcase_07 AC 58 ms
59,780 KB
testcase_08 AC 51 ms
59,780 KB
testcase_09 AC 58 ms
59,780 KB
testcase_10 AC 64 ms
59,780 KB
testcase_11 AC 49 ms
59,780 KB
testcase_12 AC 44 ms
59,780 KB
testcase_13 AC 49 ms
59,780 KB
testcase_14 AC 45 ms
59,780 KB
testcase_15 AC 51 ms
59,780 KB
testcase_16 AC 65 ms
59,780 KB
testcase_17 AC 65 ms
59,780 KB
testcase_18 AC 37 ms
53,496 KB
testcase_19 AC 38 ms
53,496 KB
testcase_20 AC 38 ms
53,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

N,p = map(int,input().split())

s = 1
ds = 1

if N == 1:
    print (0)
    sys.exit()
elif N == 2:
    print (1)
    sys.exit()

a = 0
b = 1
mod = 10**9+7

for i in range(N-2):

    newb = b*p+a
    newa = b

    a = newa % mod
    b = newb % mod

    s += b
    ds += b**2
    s %= mod
    ds %= mod

print ((s**2+ds) * pow(2,mod-2,mod) % mod )

    
0