結果

問題 No.978 Fibonacci Convolution Easy
ユーザー 37zigen37zigen
提出日時 2020-01-31 22:00:00
言語 Java19
(openjdk 21)
結果
AC  
実行時間 242 ms / 2,000 ms
コード長 802 bytes
コンパイル時間 3,228 ms
コンパイル使用メモリ 78,092 KB
実行使用メモリ 108,076 KB
最終ジャッジ日時 2023-10-19 01:02:51
合計ジャッジ時間 8,058 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 219 ms
107,720 KB
testcase_01 AC 231 ms
107,848 KB
testcase_02 AC 231 ms
107,828 KB
testcase_03 AC 242 ms
108,060 KB
testcase_04 AC 229 ms
107,856 KB
testcase_05 AC 227 ms
105,912 KB
testcase_06 AC 231 ms
108,048 KB
testcase_07 AC 228 ms
108,068 KB
testcase_08 AC 232 ms
107,996 KB
testcase_09 AC 231 ms
107,972 KB
testcase_10 AC 239 ms
107,788 KB
testcase_11 AC 234 ms
105,908 KB
testcase_12 AC 235 ms
107,508 KB
testcase_13 AC 229 ms
107,860 KB
testcase_14 AC 227 ms
107,852 KB
testcase_15 AC 230 ms
108,076 KB
testcase_16 AC 234 ms
107,812 KB
testcase_17 AC 241 ms
107,856 KB
testcase_18 AC 229 ms
107,816 KB
testcase_19 AC 224 ms
107,844 KB
testcase_20 AC 222 ms
107,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

// This file is a "Hello, world!" in Java language by OpenJDK for wandbox.

class Main
{
	public static void main(String[] args)
	{
		new Main().run();
	}
	
	final long m=(long)1e9+7;
	
	void run(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		long p=sc.nextLong();
		long[] a=new long[(int)(3e6)];
		long[] s=new long[(int)(3e6)];
		a[1]=0;
		a[2]=1;
		for(int i=3;i<a.length;++i)a[i]=(p*a[i-1]%m+a[i-2])%m;
		for(int i=1;i<a.length;++i)s[i]=(s[i-1]+a[i])%m;
		long ans=0;
		for(int i=1;i<=N;++i){
			ans=(ans+s[i]*a[i]%m)%m;
		}
		System.out.println(ans);
	}
	
	void tr(Object...o){System.out.println(Arrays.deepToString(o));}
}
// OpenJDK reference:
//   http://openjdk.java.net/

// Java language references:
//   http://docs.oracle.com/javase
0