結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー sasa
提出日時 2025-03-19 13:52:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 242 bytes
コンパイル時間 355 ms
コンパイル使用メモリ 27,264 KB
実行使用メモリ 7,324 KB
最終ジャッジ日時 2025-03-19 13:52:46
合計ジャッジ時間 1,643 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:4:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    4 |         scanf("%lld%lld",&val,&mod);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/stdio.h:980,
                 from main.cpp:1:
In function ‘int printf(const char*, ...)’,
    inlined from ‘int main()’ at main.cpp:14:8:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:86:23: warning: ‘f3’ may be used uninitialized [-Wmaybe-uninitialized]
   86 |   return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
      |          ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:6:31: note: ‘f3’ was declared here
    6 |         long long int f1, f2, f3;
      |                               ^~

ソースコード

diff #

#include <stdio.h>
int main(void){
	long long val,mod;
	scanf("%lld%lld",&val,&mod);
	
	long long int f1, f2, f3;
	f1 = 0;
	f2 = 1;
	for (long long i = 2;i < val;i ++){
		f3 = (f1 + f2) % mod;
		f1 = f2;
		f2 = f3;
	}
	printf("%lld\n", f3);
}
0