結果
問題 | No.526 フィボナッチ数列の第N項をMで割った余りを求める |
ユーザー |
![]() |
提出日時 | 2017-06-09 22:38:14 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 387 ms / 2,000 ms |
コード長 | 1,252 bytes |
コンパイル時間 | 829 ms |
コンパイル使用メモリ | 114,076 KB |
実行使用メモリ | 296,752 KB |
最終ジャッジ日時 | 2024-09-22 15:29:43 |
合計ジャッジ時間 | 3,235 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;using System.Linq;using System.IO;using System.Collections.Generic;class Solution{long N, M;long[] memo;long fib(long i){if (i == 0) return 0;if (i == 1) return 1;if (memo[i] > 0) return memo[i];return memo[i] = (fib(i - 1) + fib(i - 2)) % M;}public void solve(TextReader input, TextWriter output){string[] lines = input.ReadLine().Split(' ');N = long.Parse(lines[0]);M = long.Parse(lines[1]);memo = new long[N + 1];output.WriteLine(fib(N-1));}}class CaideConstants {public const string InputFile = null;public const string OutputFile = null;}public class Program {public static void Main(string[] args) {Solution solution = new Solution();using (System.IO.TextReader input =CaideConstants.InputFile == null ? System.Console.In :new System.IO.StreamReader(CaideConstants.InputFile))using (System.IO.TextWriter output =CaideConstants.OutputFile == null ? System.Console.Out:new System.IO.StreamWriter(CaideConstants.OutputFile))solution.solve(input, output);}}