結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー snzt_pt
提出日時 2017-06-22 11:34:38
言語 Java
(openjdk 23)
結果
TLE  
実行時間 -
コード長 435 bytes
コンパイル時間 2,267 ms
コンパイル使用メモリ 74,208 KB
実行使用メモリ 61,292 KB
最終ジャッジ日時 2024-10-02 11:57:15
合計ジャッジ時間 8,041 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 TLE * 1 -- * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		System.out.println(calc(n,m));
	}

	static int calc(int n, int m){
		if(n == 2){
			return 1;
		}
		else if (n == 1) {
			return 0;
		}else{
			return (calc(n-1, m) + calc(n-2, m)) % m;
		}
	}
}
0