結果

問題 No.978 Fibonacci Convolution Easy
ユーザー takakintakakin
提出日時 2020-05-24 16:34:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 440 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 174,060 KB
最終ジャッジ日時 2024-04-20 02:05:30
合計ジャッジ時間 5,859 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
18,048 KB
testcase_01 AC 1,349 ms
71,756 KB
testcase_02 AC 640 ms
41,672 KB
testcase_03 TLE -
testcase_04 AC 755 ms
48,976 KB
testcase_05 AC 177 ms
18,760 KB
testcase_06 AC 1,006 ms
63,688 KB
testcase_07 AC 1,875 ms
108,104 KB
testcase_08 AC 1,263 ms
77,896 KB
testcase_09 TLE -
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

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=p*A[-1]+A[-2]
    if a>=mod:
      a%=mod
    b=pow(a,2,mod)
    A.append(a)
    B.append(b)
  a,b=0,0
  for i in range(n):
    a+=A[i]
    if a>=mod:
      a%=mod
    b+=B[i]
    if b>=mod:
      b%=mod
  print(((a**2+b)*pow(2,mod-2,mod))%mod)
  
0