結果

問題 No.978 Fibonacci Convolution Easy
ユーザー htensai
提出日時 2020-02-03 12:35:34
言語 Java
(openjdk 23)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 2,691 ms
コンパイル使用メモリ 74,340 KB
実行使用メモリ 54,328 KB
最終ジャッジ日時 2024-09-18 21:40:33
合計ジャッジ時間 6,396 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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