結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー aru_creatoraru_creator
提出日時 2018-11-22 20:47:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 423 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 11,008 KB
実行使用メモリ 33,948 KB
最終ジャッジ日時 2023-08-26 04:01:07
合計ジャッジ時間 7,917 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
33,948 KB
testcase_01 AC 111 ms
29,540 KB
testcase_02 AC 109 ms
29,556 KB
testcase_03 AC 111 ms
29,628 KB
testcase_04 AC 117 ms
29,572 KB
testcase_05 AC 111 ms
29,488 KB
testcase_06 AC 118 ms
29,556 KB
testcase_07 AC 115 ms
29,648 KB
testcase_08 AC 139 ms
29,520 KB
testcase_09 AC 350 ms
29,532 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np 

def calFibonatti(N,M):
    if N<=3:
        if N == 1:
            return 0
        return 1
    N = N - 3
    
    
    A = np.zeros((2,2), dtype='int32')
    A[0][0]=1
    A[0][1]=1
    A[1][0]=1
    A[1][1]=0
    
    result = np.copy(A)
    
    for i in range(N):
        result = np.mod(result.dot(A),M)
    
    return result[0][0]




N,M =  map(int, input().split())

print(calFibonatti(N, M))
0