結果
問題 | No.526 フィボナッチ数列の第N項をMで割った余りを求める |
ユーザー |
![]() |
提出日時 | 2017-06-09 22:28:09 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 1,427 ms / 2,000 ms |
コード長 | 1,297 bytes |
コンパイル時間 | 902 ms |
コンパイル使用メモリ | 114,208 KB |
実行使用メモリ | 479,212 KB |
最終ジャッジ日時 | 2024-09-22 15:09:10 |
合計ジャッジ時間 | 7,820 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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.IO;using System.Linq;using System.Collections.Generic;public class Program{public void Proc(){int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();int num = inpt[0];this.Mod = inpt[1];long ans = GetAns(num);Console.WriteLine(ans);}private Dictionary<int, long> dic = new Dictionary<int, long>();private long GetAns(int num) {if(num <= 1) {return 0;}if(num == 2) {return 1;}if(dic.ContainsKey(num)) {return dic[num];}long ans = (GetAns(num - 1) + GetAns(num - 2)) % Mod;dic[num] = ans;return ans;}private int Mod = 0;public class Reader{private static StringReader sr;public static bool IsDebug = false;public static string ReadLine(){if (IsDebug){if (sr == null){sr = new StringReader(InputText.Trim());}return sr.ReadLine();}else{return Console.ReadLine();}}private static string InputText = @"10 20";}public static void Main(string[] args){#if DEBUGReader.IsDebug = true;#endifProgram prg = new Program();prg.Proc();}}