結果
問題 | No.526 フィボナッチ数列の第N項をMで割った余りを求める |
ユーザー |
|
提出日時 | 2021-12-15 07:01:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 302 bytes |
コンパイル時間 | 2,011 ms |
コンパイル使用メモリ | 191,660 KB |
最終ジャッジ日時 | 2025-01-26 22:56:17 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; long long int f[5000001]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); long long int n,m; cin >> n >> m; f[1] = 0; f[2] = 1; for(int i=3;i<=n;i++) { f[i] = f[i-1] + f[i-2]; f[i]%=m; } cout << f[n] << '\n'; return 0; }