結果

問題 No.978 Fibonacci Convolution Easy
ユーザー htensaihtensai
提出日時 2020-02-03 12:35:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 339 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 2,861 ms
コンパイル使用メモリ 74,664 KB
実行使用メモリ 57,804 KB
最終ジャッジ日時 2023-10-19 01:42:33
合計ジャッジ時間 8,230 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
57,456 KB
testcase_01 AC 151 ms
57,656 KB
testcase_02 AC 148 ms
57,804 KB
testcase_03 AC 155 ms
57,636 KB
testcase_04 AC 151 ms
57,140 KB
testcase_05 AC 148 ms
57,104 KB
testcase_06 AC 165 ms
57,280 KB
testcase_07 AC 165 ms
57,456 KB
testcase_08 AC 160 ms
57,684 KB
testcase_09 AC 163 ms
57,640 KB
testcase_10 AC 162 ms
57,268 KB
testcase_11 AC 152 ms
57,512 KB
testcase_12 AC 152 ms
57,624 KB
testcase_13 AC 211 ms
57,140 KB
testcase_14 AC 330 ms
57,128 KB
testcase_15 AC 326 ms
56,984 KB
testcase_16 AC 331 ms
56,964 KB
testcase_17 AC 339 ms
56,996 KB
testcase_18 AC 255 ms
57,012 KB
testcase_19 AC 294 ms
57,028 KB
testcase_20 AC 214 ms
57,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int p = sc.nextInt();
        long prepre = 0;
        long pre = 1;
        long sum = 1;
        long total = 1;
        if (n == 1) {
            System.out.println(0);
            return;
        } else if (n == 1) {
            System.out.println(1);
            return;
        }
        for (int i = 3; i <= n; i++) {
            long x = pre * p + prepre;
            x %= MOD;
            sum += x;
            sum %= MOD;
            total += sum * x;
            total %= MOD;
            prepre = pre;
            pre = x;
        }
        System.out.println(total);
    }
}
0