結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー bluemeganebluemegane
提出日時 2018-09-12 16:40:19
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 470 bytes
コンパイル時間 2,038 ms
コンパイル使用メモリ 103,220 KB
実行使用メモリ 59,116 KB
最終ジャッジ日時 2023-09-09 10:39:31
合計ジャッジ時間 4,083 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
22,632 KB
testcase_01 AC 56 ms
22,668 KB
testcase_02 AC 56 ms
20,732 KB
testcase_03 AC 56 ms
20,820 KB
testcase_04 AC 56 ms
20,648 KB
testcase_05 AC 56 ms
20,592 KB
testcase_06 AC 56 ms
20,632 KB
testcase_07 AC 56 ms
20,652 KB
testcase_08 AC 57 ms
22,672 KB
testcase_09 AC 59 ms
18,712 KB
testcase_10 AC 77 ms
27,948 KB
testcase_11 AC 150 ms
59,052 KB
testcase_12 AC 148 ms
59,116 KB
testcase_13 AC 150 ms
59,044 KB
testcase_14 AC 150 ms
57,168 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]);
        Console.WriteLine(getAns(n, m));
    }
    public static long getAns(long n, long m)
    {
        var a = new long[n + 1];
        a[2] = 1;
        for (int i = 3; i <= n; i++)
            a[i] = (a[i - 1] + a[i - 2]) % m;
        return a[n];
    }
}
0