結果
問題 |
No.526 フィボナッチ数列の第N項をMで割った余りを求める
|
ユーザー |
![]() |
提出日時 | 2025-05-13 16:40:09 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 78 ms / 2,000 ms |
コード長 | 647 bytes |
コンパイル時間 | 3,324 ms |
コンパイル使用メモリ | 273,832 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-05-13 16:40:14 |
合計ジャッジ時間 | 4,387 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif #include<bits/stdc++.h> using namespace std; using ll = long long; #define YES cout<<"Yes"<<endl #define NO cout<<"No"<<endl #define YN {cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}// if(a==b)YN; #define NO2 cout<<-1<<endl #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rrep(i, n) for (int i=int(n)-1; i>=0; --i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() int main() { int N, M; cin >> N >> M; ll an=0, an1=0, an2=1; for (int i=2; i<N; i++) { an = an1; an1 = an2; an2 = (an+an1)%M; } cout << an2 << endl; }