結果

問題 No.978 Fibonacci Convolution Easy
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2020-01-31 22:56:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 363 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 11,872 KB
実行使用メモリ 10,176 KB
最終ジャッジ日時 2023-10-17 11:44:42
合計ジャッジ時間 17,967 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
10,136 KB
testcase_01 AC 819 ms
10,136 KB
testcase_02 AC 416 ms
10,136 KB
testcase_03 AC 1,991 ms
10,176 KB
testcase_04 AC 508 ms
10,136 KB
testcase_05 AC 129 ms
10,136 KB
testcase_06 AC 699 ms
10,136 KB
testcase_07 AC 1,254 ms
10,136 KB
testcase_08 AC 872 ms
10,136 KB
testcase_09 AC 1,411 ms
10,136 KB
testcase_10 AC 1,991 ms
10,136 KB
testcase_11 AC 583 ms
10,136 KB
testcase_12 AC 119 ms
10,136 KB
testcase_13 AC 681 ms
10,136 KB
testcase_14 AC 217 ms
10,136 KB
testcase_15 AC 778 ms
10,136 KB
testcase_16 TLE -
testcase_17 AC 1,998 ms
10,176 KB
testcase_18 AC 30 ms
10,136 KB
testcase_19 AC 30 ms
10,136 KB
testcase_20 AC 30 ms
10,136 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