結果

問題 No.978 Fibonacci Convolution Easy
ユーザー chinchillachinchilla
提出日時 2020-02-03 05:09:46
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 496 ms / 2,000 ms
コード長 356 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 11,980 KB
実行使用メモリ 42,652 KB
最終ジャッジ日時 2023-10-19 01:40:00
合計ジャッジ時間 12,282 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 494 ms
42,652 KB
testcase_01 AC 487 ms
42,652 KB
testcase_02 AC 496 ms
42,652 KB
testcase_03 AC 491 ms
42,652 KB
testcase_04 AC 489 ms
42,652 KB
testcase_05 AC 490 ms
42,652 KB
testcase_06 AC 483 ms
42,652 KB
testcase_07 AC 483 ms
42,652 KB
testcase_08 AC 492 ms
42,652 KB
testcase_09 AC 491 ms
42,652 KB
testcase_10 AC 487 ms
42,652 KB
testcase_11 AC 490 ms
42,652 KB
testcase_12 AC 489 ms
42,652 KB
testcase_13 AC 488 ms
42,652 KB
testcase_14 AC 483 ms
42,652 KB
testcase_15 AC 493 ms
42,652 KB
testcase_16 AC 492 ms
42,652 KB
testcase_17 AC 487 ms
42,652 KB
testcase_18 AC 485 ms
42,652 KB
testcase_19 AC 481 ms
42,652 KB
testcase_20 AC 493 ms
42,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
m = 1000000007
n, p = map(int, input().split())
def mpow(b, i):
	if i == 0: return 1
	p = mpow(b, i>>1)**2 % m
	return p * b % m if i & 1 else p
r = mpow(p, m-2)
h = (m+1)//2
c = np.matrix([[p, 1], [1, 0]], 'i8')
u, v = (np.matrix([1, 0]) * mpow(c, n-1)).flat
s = (u + v - 1) * r % m
t = (u * v % m) * r % m
print((s**2 + t) % m * h % m)
0