結果

問題 No.978 Fibonacci Convolution Easy
ユーザー maspy
提出日時 2020-01-31 23:02:10
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 1,262 ms / 2,000 ms
コード長 395 bytes
コンパイル時間 67 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 89,124 KB
最終ジャッジ日時 2024-09-18 21:03:41
合計ジャッジ時間 10,741 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

if N == 1:
    print(0)
    exit()

MOD = 10 ** 9 + 7

A = [0] * (N+1)
A[2] = 1
for n in range(3,N+1):
    A[n] = (A[n-1] * p + A[n-2]) % MOD

S1 = sum(A)
S2 = sum(x**2 for x in A)

S = (S1**2 + S2) % MOD
if S&1:
    S += MOD

S //= 2
print(S)
0