結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー bluemeganebluemegane
提出日時 2018-09-12 16:32:16
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 487 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 2,288 ms
コンパイル使用メモリ 104,152 KB
実行使用メモリ 295,640 KB
最終ジャッジ日時 2023-09-09 10:10:54
合計ジャッジ時間 5,530 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
20,708 KB
testcase_01 AC 55 ms
18,584 KB
testcase_02 AC 57 ms
22,716 KB
testcase_03 AC 56 ms
20,716 KB
testcase_04 AC 56 ms
22,672 KB
testcase_05 AC 57 ms
22,744 KB
testcase_06 AC 56 ms
20,732 KB
testcase_07 AC 58 ms
20,864 KB
testcase_08 AC 57 ms
21,172 KB
testcase_09 AC 65 ms
25,588 KB
testcase_10 AC 126 ms
76,780 KB
testcase_11 AC 487 ms
295,640 KB
testcase_12 AC 424 ms
293,564 KB
testcase_13 AC 366 ms
295,552 KB
testcase_14 AC 363 ms
293,452 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = long.Parse(line[0]);
        var m = long.Parse(line[1]);
        var a = new long[n + 1];
        a[2] = 1;
        Console.WriteLine(Func(a, n, m));
    }
    public static long Func(long    [] a, long n, long m)
    {
        if (n == 1) return 0;
        if (n == 2) return 1;
        if (a[n] != 0) return a[n];
        else
        {
            var w1 = Func(a, n - 1, m);
            var w2 = Func(a, n - 2, m);
            a[n] = (w1 + w2) % m;
            return a[n];
        }
    }
}
0