結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー muz_808muz_808
提出日時 2017-06-09 22:41:19
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 1,494 bytes
コンパイル時間 979 ms
コンパイル使用メモリ 110,712 KB
実行使用メモリ 24,188 KB
最終ジャッジ日時 2023-10-23 22:12:42
合計ジャッジ時間 2,418 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
24,184 KB
testcase_01 AC 25 ms
24,184 KB
testcase_02 AC 25 ms
24,184 KB
testcase_03 AC 25 ms
24,184 KB
testcase_04 AC 26 ms
24,184 KB
testcase_05 AC 25 ms
24,184 KB
testcase_06 AC 25 ms
24,184 KB
testcase_07 AC 25 ms
24,184 KB
testcase_08 AC 25 ms
24,184 KB
testcase_09 AC 28 ms
24,188 KB
testcase_10 AC 41 ms
24,184 KB
testcase_11 AC 104 ms
24,188 KB
testcase_12 AC 104 ms
24,184 KB
testcase_13 AC 104 ms
24,188 KB
testcase_14 AC 104 ms
24,188 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    private static readonly Scanner sc = new Scanner();
    static void Main(string[] args)
    {
        long n = sc.Long;
        long m = sc.Long;

        long fib1 = 0;
        long fib2 = 1;

        if (n == 1 || n == 2)
        {
            Console.WriteLine(n == 1 ? 0 : 1);
            return;
        }

        for (var i = 3; i <= n; i++)
        {
            long tmp = fib1 + fib2;
            fib1 = fib2;
            fib2 = tmp % m;
        }

        Console.WriteLine(fib2 % m);
    }
}

class Scanner
{
    private string[] _str = new string[0];
    private int _i;

    public string Line { get { return Console.ReadLine(); } }

    public string Str
    {
        get
        {
            if (_i >= _str.Length)
            {
                _str = Line.Split(' ');
                _i = 0;
            }
            return _str[_i++];
        }
    }

    public string[] StrArr { get { return Line.Split(' '); } }
    public int Int { get { return int.Parse(Str); } }
    public int[] IntArr { get { return Line.Split(' ').Select(int.Parse).ToArray(); } }
    public long Long { get { return long.Parse(Str); } }
    public long[] LongArr { get { return Line.Split(' ').Select(long.Parse).ToArray(); } }
    public double Double { get { return double.Parse(Str); } }
    public double[] DoubleArr { get { return Line.Split(' ').Select(double.Parse).ToArray(); } }
}
0