結果
問題 | No.534 フィボナッチフィボナッチ数 |
ユーザー | Chihaya_chan |
提出日時 | 2020-08-09 13:56:44 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 834 bytes |
コンパイル時間 | 157 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 44,732 KB |
最終ジャッジ日時 | 2024-04-15 03:51:16 |
合計ジャッジ時間 | 22,738 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 474 ms
44,340 KB |
testcase_01 | AC | 479 ms
44,472 KB |
testcase_02 | AC | 474 ms
43,960 KB |
testcase_03 | AC | 472 ms
44,348 KB |
testcase_04 | AC | 472 ms
44,344 KB |
testcase_05 | AC | 475 ms
43,956 KB |
testcase_06 | AC | 481 ms
43,996 KB |
testcase_07 | AC | 479 ms
44,348 KB |
testcase_08 | AC | 474 ms
43,960 KB |
testcase_09 | AC | 473 ms
44,340 KB |
testcase_10 | AC | 473 ms
44,600 KB |
testcase_11 | AC | 487 ms
44,340 KB |
testcase_12 | AC | 471 ms
44,480 KB |
testcase_13 | AC | 476 ms
43,960 KB |
testcase_14 | AC | 480 ms
44,600 KB |
testcase_15 | AC | 471 ms
44,064 KB |
testcase_16 | AC | 476 ms
44,216 KB |
testcase_17 | AC | 479 ms
44,096 KB |
testcase_18 | AC | 477 ms
43,968 KB |
testcase_19 | AC | 498 ms
44,088 KB |
testcase_20 | AC | 491 ms
44,088 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
ソースコード
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, mod) print(Fibonacci(fibN, mod))