結果

問題 No.978 Fibonacci Convolution Easy
ユーザー takakintakakin
提出日時 2020-05-24 16:32:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 362 bytes
コンパイル時間 373 ms
コンパイル使用メモリ 82,572 KB
実行使用メモリ 237,696 KB
最終ジャッジ日時 2024-04-20 01:59:03
合計ジャッジ時間 3,445 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
63,316 KB
testcase_01 AC 117 ms
170,720 KB
testcase_02 AC 89 ms
120,596 KB
testcase_03 AC 207 ms
237,696 KB
testcase_04 AC 93 ms
128,868 KB
testcase_05 AC 52 ms
75,292 KB
testcase_06 AC 110 ms
157,416 KB
testcase_07 AC 150 ms
237,200 KB
testcase_08 AC 128 ms
183,260 KB
testcase_09 AC 175 ms
237,328 KB
testcase_10 AC 207 ms
237,120 KB
testcase_11 AC 106 ms
145,912 KB
testcase_12 AC 52 ms
73,008 KB
testcase_13 AC 112 ms
157,348 KB
testcase_14 AC 62 ms
86,940 KB
testcase_15 AC 116 ms
169,772 KB
testcase_16 AC 218 ms
236,636 KB
testcase_17 AC 210 ms
236,944 KB
testcase_18 AC 35 ms
53,620 KB
testcase_19 AC 37 ms
52,200 KB
testcase_20 AC 35 ms
52,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n,p=map(int,input().split())
mod=10**9+7
if n==1:
  print(0)
elif n==2:
  print(1)
else:
  A=[0,1]
  B=[0,1]
  for _ in range(n-2):
    A.append((p*A[-1]+A[-2])%mod)
    B.append((A[-1]**2)%mod)
  a,b=0,0
  for i in range(n):
    a=(a+A[i])%mod
    b=(b+B[i])%mod
  print(((a**2+b)*pow(2,mod-2,mod))%mod)
  
0