結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー tomokinex
提出日時 2017-06-22 11:11:36
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 214 bytes
コンパイル時間 409 ms
コンパイル使用メモリ 54,648 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-02 10:13:16
合計ジャッジ時間 1,294 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;
int main() {
  int n,m;
  cin >> n >> m;
  long a = 0,b = 1,ans;
  for(int i=0;i<n-2;i++){
    ans = (a+b)%m;
    a = b;
    b = ans;
  }
  cout << ans << endl;
  return 0;
}
0