結果

問題 No.534 フィボナッチフィボナッチ数
ユーザー Chihaya_chanChihaya_chan
提出日時 2020-08-09 14:07:40
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 674 ms / 2,000 ms
コード長 828 bytes
コンパイル時間 130 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 44,476 KB
最終ジャッジ日時 2024-04-15 04:06:15
合計ジャッジ時間 22,210 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 469 ms
43,956 KB
testcase_01 AC 472 ms
44,248 KB
testcase_02 AC 466 ms
44,220 KB
testcase_03 AC 470 ms
44,224 KB
testcase_04 AC 458 ms
44,220 KB
testcase_05 AC 464 ms
44,352 KB
testcase_06 AC 468 ms
44,344 KB
testcase_07 AC 473 ms
43,836 KB
testcase_08 AC 469 ms
44,092 KB
testcase_09 AC 470 ms
44,100 KB
testcase_10 AC 464 ms
44,208 KB
testcase_11 AC 472 ms
44,100 KB
testcase_12 AC 467 ms
44,092 KB
testcase_13 AC 489 ms
44,220 KB
testcase_14 AC 469 ms
43,992 KB
testcase_15 AC 471 ms
44,220 KB
testcase_16 AC 472 ms
43,832 KB
testcase_17 AC 475 ms
43,836 KB
testcase_18 AC 468 ms
44,340 KB
testcase_19 AC 474 ms
44,216 KB
testcase_20 AC 455 ms
44,476 KB
testcase_21 AC 467 ms
44,220 KB
testcase_22 AC 466 ms
43,840 KB
testcase_23 AC 674 ms
44,020 KB
testcase_24 AC 465 ms
44,212 KB
testcase_25 AC 467 ms
44,220 KB
testcase_26 AC 469 ms
43,956 KB
testcase_27 AC 465 ms
43,960 KB
testcase_28 AC 465 ms
44,348 KB
testcase_29 AC 475 ms
44,224 KB
testcase_30 AC 471 ms
44,476 KB
testcase_31 AC 477 ms
43,968 KB
testcase_32 AC 482 ms
44,344 KB
testcase_33 AC 483 ms
44,344 KB
testcase_34 AC 470 ms
44,224 KB
testcase_35 AC 472 ms
44,344 KB
testcase_36 AC 466 ms
43,828 KB
testcase_37 AC 469 ms
44,472 KB
testcase_38 AC 466 ms
44,216 KB
testcase_39 AC 473 ms
43,968 KB
testcase_40 AC 468 ms
44,352 KB
testcase_41 AC 471 ms
44,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
N = int(input())
mod = 10**9 + 7
cycle = 2000000016


def matrix_power(A, N, mod):
    # returnA^N %mod in O(K**3 log N). (K is the size of A.)
    assert A.shape[0] == A.shape[1]
    K = A.shape[0]
    if N == 0:
        return np.eye(K, dtype=np.int64)
    else:
        if N % 2 == 0:
            mat = matrix_power(A, N//2, mod)
            return np.dot(mat, mat) % mod
        else:
            mat = matrix_power(A, N//2, mod)
            return np.dot(np.dot(mat, mat) % mod, A) % mod


def Fibonacci(N, mod):
    # return the n-th term of the fivonacci sequence  in O(logN).
    # F0=0,F1=1
    d = np.array([1, 0])
    A = np.array([[1, 1], [1, 0]], dtype=np.int64)
    res = np.dot(matrix_power(A, N, mod), d)
    return int(res[-1]) % mod


fibN = Fibonacci(N ,cycle)
print(Fibonacci(fibN, mod))
0