結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー shinwisteria
提出日時 2018-03-13 20:20:24
言語 Java
(openjdk 23)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 346 bytes
コンパイル時間 3,404 ms
コンパイル使用メモリ 73,912 KB
実行使用メモリ 41,752 KB
最終ジャッジ日時 2024-11-23 15:26:54
合計ジャッジ時間 6,752 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

package m.shin;
import java.util.Scanner;
public class Con526 {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		long m = s.nextLong();
		s.close();

		long a1 = 0,a2 = 1;
		for(int i = 3;i <= n;i++){
			long ai = (a1 + a2) % m;
			a1 = a2;
			a2 = ai;
		}
		System.out.println(a2);

	}

}
0