結果

問題 No.978 Fibonacci Convolution Easy
ユーザー r_ishidar_ishida
提出日時 2020-02-01 18:21:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,035 ms / 2,000 ms
コード長 281 bytes
コンパイル時間 691 ms
コンパイル使用メモリ 11,836 KB
実行使用メモリ 88,608 KB
最終ジャッジ日時 2023-10-19 01:11:51
合計ジャッジ時間 9,696 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
10,972 KB
testcase_01 AC 429 ms
40,736 KB
testcase_02 AC 231 ms
25,632 KB
testcase_03 AC 986 ms
85,388 KB
testcase_04 AC 272 ms
29,344 KB
testcase_05 AC 82 ms
14,240 KB
testcase_06 AC 365 ms
36,568 KB
testcase_07 AC 658 ms
58,896 KB
testcase_08 AC 461 ms
43,796 KB
testcase_09 AC 755 ms
66,120 KB
testcase_10 AC 1,035 ms
88,448 KB
testcase_11 AC 314 ms
32,404 KB
testcase_12 AC 78 ms
13,792 KB
testcase_13 AC 368 ms
36,112 KB
testcase_14 AC 123 ms
17,500 KB
testcase_15 AC 408 ms
39,824 KB
testcase_16 AC 1,029 ms
88,608 KB
testcase_17 AC 1,016 ms
88,356 KB
testcase_18 AC 29 ms
10,144 KB
testcase_19 AC 29 ms
10,144 KB
testcase_20 AC 29 ms
10,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, p = map(int,input().split())
MOD = 10**9+7
if n == 1:
    print(0)
    exit(0)
elif n == 2:
    print(1)
    exit(0)
a = [0, 1]
for i in range(n-2):
    a.append((a[i+1]*p+a[i])%MOD)
s = sum(i**2 for i in a)
ans = (pow(sum(a), 2, MOD)+s)*pow(2, MOD-2, MOD)
ans %= MOD
print(ans)
0