結果

問題 No.534 フィボナッチフィボナッチ数
ユーザー maspymaspy
提出日時 2020-03-24 02:20:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 1,075 bytes
コンパイル時間 255 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 29,776 KB
最終ジャッジ日時 2023-08-28 18:36:21
合計ジャッジ時間 9,573 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
29,680 KB
testcase_01 AC 147 ms
29,692 KB
testcase_02 AC 140 ms
29,584 KB
testcase_03 AC 138 ms
29,644 KB
testcase_04 AC 140 ms
29,692 KB
testcase_05 AC 138 ms
29,564 KB
testcase_06 AC 138 ms
29,580 KB
testcase_07 AC 139 ms
29,588 KB
testcase_08 AC 139 ms
29,648 KB
testcase_09 AC 138 ms
29,776 KB
testcase_10 AC 140 ms
29,708 KB
testcase_11 AC 135 ms
29,692 KB
testcase_12 AC 135 ms
29,588 KB
testcase_13 AC 137 ms
29,688 KB
testcase_14 AC 138 ms
29,708 KB
testcase_15 AC 137 ms
29,644 KB
testcase_16 AC 134 ms
29,484 KB
testcase_17 AC 136 ms
29,580 KB
testcase_18 AC 135 ms
29,660 KB
testcase_19 AC 135 ms
29,596 KB
testcase_20 AC 137 ms
29,672 KB
testcase_21 AC 141 ms
29,632 KB
testcase_22 AC 136 ms
29,580 KB
testcase_23 AC 136 ms
29,680 KB
testcase_24 AC 138 ms
29,688 KB
testcase_25 AC 140 ms
29,548 KB
testcase_26 AC 137 ms
29,628 KB
testcase_27 AC 137 ms
29,720 KB
testcase_28 AC 136 ms
29,668 KB
testcase_29 AC 138 ms
29,624 KB
testcase_30 AC 138 ms
29,712 KB
testcase_31 AC 141 ms
29,724 KB
testcase_32 AC 140 ms
29,560 KB
testcase_33 AC 135 ms
29,632 KB
testcase_34 AC 137 ms
29,576 KB
testcase_35 AC 134 ms
29,584 KB
testcase_36 AC 135 ms
29,652 KB
testcase_37 AC 135 ms
29,732 KB
testcase_38 AC 138 ms
29,604 KB
testcase_39 AC 138 ms
29,732 KB
testcase_40 AC 136 ms
29,588 KB
testcase_41 AC 137 ms
29,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(read())
MOD = 10 ** 9 + 7
MOD1 = (MOD + 1) * 2


def coef_of_generating_function(P, Q, N, MOD):
    """compute the coefficient [x^N] P/Q of rational power series.

    Parameters
    ----------
    P : np.ndarray
        numerator.
    Q : np.ndarray
        denominator
        Q[0] == 1 and len(Q) == len(P) + 1 is assumed.
    N : int
        The coefficient to compute.
    """
    def convolve(f, g):
        return np.convolve(f, g) % MOD

    while N:
        Q1 = Q.copy()
        Q1[1::2] = np.negative(Q1[1::2])
        if N & 1:
            P = convolve(P, Q1)[1::2]
        else:
            P = convolve(P, Q1)[::2]
        Q = convolve(Q, Q1)[::2]
        N >>= 1
    return P[0]


def fibonacci_mod(N, MOD):
    P = np.array([0, 1], np.int64)
    Q = np.array([1, -1, -1], np.int64)
    return coef_of_generating_function(P, Q, N, MOD)


F = fibonacci_mod(N, MOD1)
print(fibonacci_mod(F, MOD))
0