結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 0 ms
4,348 KB
testcase_05 AC 0 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 14 ms
9,588 KB
testcase_11 AC 62 ms
40,776 KB
testcase_12 AC 62 ms
40,776 KB
testcase_13 AC 62 ms
40,776 KB
testcase_14 AC 62 ms
40,776 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];
    dp[i] %= m;
  }
  let ans = dp[n-1] % m;
  println!("{}", ans);
}
0