結果
| 問題 | No.526 フィボナッチ数列の第N項をMで割った余りを求める |
| コンテスト | |
| ユーザー |
u-sho
|
| 提出日時 | 2017-06-09 23:11:23 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 32 ms / 2,000 ms |
| コード長 | 272 bytes |
| 記録 | |
| コンパイル時間 | 314 ms |
| コンパイル使用メモリ | 71,888 KB |
| 実行使用メモリ | 7,976 KB |
| 最終ジャッジ日時 | 2026-04-11 00:47:34 |
| 合計ジャッジ時間 | 1,336 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
コンパイルメッセージ
main.cpp: In function 'long long int fib(int, long long int)':
main.cpp:10:10: warning: 'c' may be used uninitialized [-Wmaybe-uninitialized]
10 | return c;
| ^
main.cpp:4:21: note: 'c' was declared here
4 | long long a=0,b=1,c;
| ^
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/iostream:43,
from main.cpp:1:
In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]',
inlined from 'int main()' at main.cpp:15:20:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:212:25: warning: 'c' may be used uninitialized [-Wmaybe-uninitialized]
212 | { return _M_insert(__n); }
| ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:4:21: note: 'c' was declared here
4 | long long a=0,b=1,c;
| ^
ソースコード
#include <iostream>
using namespace std;
long long fib(int n, long long m){
long long a=0,b=1,c;
for(int i=3;i<=n;i++){
c=(a+b)%m;
a=b;
b=c;
}
return c;
}
int main() {
long long n,m;
cin >> n >> m;
cout << fib(n,m) << endl;
return 0;
}
u-sho