結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー ken miuraken miura
提出日時 2021-10-18 19:56:11
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 547 bytes
コンパイル時間 1,175 ms
コンパイル使用メモリ 178,368 KB
実行使用メモリ 40,764 KB
最終ジャッジ日時 2023-10-19 19:59:11
合計ジャッジ時間 2,197 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,348 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 15 ms
40,760 KB
testcase_13 WA -
testcase_14 AC 15 ms
40,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let s = stdin();
  let s = s.lock();
  let s: String = s.bytes()
    .map(|c| c.expect("failed reading char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  s.parse().ok().expect("failed parsing")
}

fn main() {
  let n: usize = read();
  let m: usize = read();
  let mut dp = vec![0; n];
  dp[0] = 0;
  dp[1] = 1;
  for i in 2..n {
    dp[i] = dp[i-1] + dp[i-2];
  }
  let ans = dp[n-1] % m;
  println!("{}", ans);
}
0