結果

問題 No.665 Bernoulli Bernoulli
ユーザー kotatsugamekotatsugame
提出日時 2020-03-05 13:02:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 549 ms / 2,000 ms
コード長 519 bytes
コンパイル時間 473 ms
コンパイル使用メモリ 66,244 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 02:17:52
合計ジャッジ時間 9,408 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 540 ms
5,376 KB
testcase_03 AC 549 ms
5,376 KB
testcase_04 AC 518 ms
5,376 KB
testcase_05 AC 489 ms
5,376 KB
testcase_06 AC 477 ms
5,376 KB
testcase_07 AC 462 ms
5,376 KB
testcase_08 AC 456 ms
5,376 KB
testcase_09 AC 529 ms
5,376 KB
testcase_10 AC 450 ms
5,376 KB
testcase_11 AC 520 ms
5,376 KB
testcase_12 AC 492 ms
5,376 KB
testcase_13 AC 521 ms
5,376 KB
testcase_14 AC 515 ms
5,376 KB
testcase_15 AC 449 ms
5,376 KB
testcase_16 AC 473 ms
5,376 KB
testcase_17 AC 455 ms
5,376 KB
testcase_18 AC 443 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
const long mod=1e9+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long inv[10101];
long N,K;
long S[10101];
main()
{
	inv[1]=1;
	for(int i=2;i<10101;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	cin>>N>>K;
	S[0]=N%mod;
	for(int i=1;i<=K;i++)
	{
		long now=power((N+1)%mod,i+1)+mod-1;
		long Ci=1;
		for(int j=0;j<i;j++)
		{
			now=(now+mod-Ci*S[j]%mod)%mod;
			Ci=Ci*(i+1-j)%mod*inv[j+1]%mod;
		}
		now=now*inv[i+1]%mod;
		S[i]=now;
	}
	cout<<S[K]<<endl;
}
0