結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2017-06-10 02:19:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 483 bytes
コンパイル時間 4,162 ms
コンパイル使用メモリ 74,012 KB
実行使用メモリ 57,620 KB
最終ジャッジ日時 2023-10-24 04:57:06
合計ジャッジ時間 5,163 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
57,384 KB
testcase_01 AC 115 ms
56,240 KB
testcase_02 AC 126 ms
57,364 KB
testcase_03 AC 126 ms
57,352 KB
testcase_04 AC 114 ms
56,288 KB
testcase_05 AC 126 ms
57,620 KB
testcase_06 AC 127 ms
55,672 KB
testcase_07 AC 122 ms
57,340 KB
testcase_08 AC 122 ms
57,568 KB
testcase_09 AC 128 ms
57,416 KB
testcase_10 AC 143 ms
57,488 KB
testcase_11 AC 205 ms
55,196 KB
testcase_12 AC 207 ms
55,408 KB
testcase_13 AC 211 ms
57,384 KB
testcase_14 AC 211 ms
57,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long M = sc.nextLong();
        System.out.println(fucntion(N,M));
    }
    static long fucntion(long N, long M){
        long A = 0;
        long B = 1;
        if(N==0)return A;
        for(int i=2; i<N; i++){
            long C = (A+B)%M;
            A=B;
            B=C;
        }
        return B;
    }
}
0