結果
問題 | No.526 フィボナッチ数列の第N項をMで割った余りを求める |
ユーザー | Lin143rd |
提出日時 | 2022-10-25 19:06:05 |
言語 | C# (.NET 8.0.203) |
結果 |
AC
|
実行時間 | 51 ms / 2,000 ms |
コード長 | 1,612 bytes |
コンパイル時間 | 14,976 ms |
コンパイル使用メモリ | 146,796 KB |
実行使用メモリ | 165,128 KB |
最終ジャッジ日時 | 2023-09-16 16:46:47 |
合計ジャッジ時間 | 16,540 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
28,208 KB |
testcase_01 | AC | 49 ms
28,292 KB |
testcase_02 | AC | 50 ms
28,360 KB |
testcase_03 | AC | 49 ms
28,168 KB |
testcase_04 | AC | 49 ms
28,168 KB |
testcase_05 | AC | 49 ms
30,088 KB |
testcase_06 | AC | 49 ms
28,288 KB |
testcase_07 | AC | 50 ms
28,232 KB |
testcase_08 | AC | 50 ms
28,260 KB |
testcase_09 | AC | 51 ms
28,068 KB |
testcase_10 | AC | 50 ms
28,308 KB |
testcase_11 | AC | 49 ms
28,176 KB |
testcase_12 | AC | 49 ms
28,456 KB |
testcase_13 | AC | 49 ms
28,212 KB |
testcase_14 | AC | 50 ms
165,128 KB |
コンパイルメッセージ
Determining projects to restore... Restored /home/judge/data/code/main.csproj (in 124 ms). .NET 向け Microsoft (R) Build Engine バージョン 17.0.0-preview-21470-01+cb055d28f Copyright (C) Microsoft Corporation.All rights reserved. プレビュー版の .NET を使用しています。https://aka.ms/dotnet-core-preview をご覧ください main -> /home/judge/data/code/bin/Release/net6.0/main.dll main -> /home/judge/data/code/bin/Release/net6.0/publish/
ソースコード
using System; using System.IO; using System.Text; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Numerics; using System.Linq.Expressions; using System.Linq; using System.Diagnostics; public class Csharp_Work { static long m; static long[, ] Mul(long[, ] a, long[, ] b) { var res = new long[a.GetLength(0), b.GetLength(1)]; for(int i = 0; i < a.GetLength(0); ++i) { for(int j = 0; j < b.GetLength(1); ++j) { for(int k = 0; k < a.GetLength(1); ++k) { res[i, j] += a[i, k] * b[k, j]; res[i, j] %= m; } } } return res; } // 正方行列の累乗 static long[, ] Pow(long[, ] a, long n) { long lng = a.GetLength(0); var res = new long[lng, lng]; var a_tmp = a.Clone() as long[, ]; // 単位行列 for(int i = 0; i < lng; ++i) { res[i, i] = 1; } long num = n; while(num > 0) { if((num & 1) != 0) res = Mul(res, a_tmp); a_tmp = Mul(a_tmp, a_tmp); num >>= 1; } return res; } static void Main(string[] args) { var fibo = new long[2, 2]; fibo[0, 0] = 1; fibo[0, 1] = 1; fibo[1, 0] = 1; fibo[1, 1] = 0; var tmp = Console.ReadLine().Split(); long n = long.Parse(tmp[0]); m = long.Parse(tmp[1]); var res = Pow(fibo, n - 2); Console.WriteLine(res[0, 0]); } }