結果

問題 No.665 Bernoulli Bernoulli
ユーザー gazellegazelle
提出日時 2018-03-09 23:52:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 298 ms / 2,000 ms
コード長 1,633 bytes
コンパイル時間 984 ms
コンパイル使用メモリ 104,820 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 04:20:38
合計ジャッジ時間 7,553 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 295 ms
5,248 KB
testcase_01 AC 292 ms
5,376 KB
testcase_02 AC 298 ms
5,376 KB
testcase_03 AC 291 ms
5,376 KB
testcase_04 AC 294 ms
5,376 KB
testcase_05 AC 282 ms
5,376 KB
testcase_06 AC 285 ms
5,376 KB
testcase_07 AC 281 ms
5,376 KB
testcase_08 AC 292 ms
5,376 KB
testcase_09 AC 294 ms
5,376 KB
testcase_10 AC 289 ms
5,376 KB
testcase_11 AC 291 ms
5,376 KB
testcase_12 AC 293 ms
5,376 KB
testcase_13 AC 295 ms
5,376 KB
testcase_14 AC 297 ms
5,376 KB
testcase_15 AC 280 ms
5,376 KB
testcase_16 AC 283 ms
5,376 KB
testcase_17 AC 287 ms
5,376 KB
testcase_18 AC 286 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

ll _pow(ll a, ll n) {
	if(n==0) return 1;
	else {
		ll res = 1;
		ll buf = a;
		while(n>0) {
			if(n%2==1) {
				res *= buf;
				res %= MOD;
			}
			buf *= buf;
			buf %= MOD;
			n/=2;
		}
		return res;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	n%=MOD;
	vector<ll> fac(10010);
	vector<ll> revfac(10010);
	ll buf=1;
	REP(i,10010) {
		if(i!=0) {
			buf*=i;
			buf%=MOD;
		}
		fac[i]=buf;
		revfac[i]=_pow(buf,MOD-2);
	}
	vector<ll> ber(10010,0);
	ber[0]=fac[10009];
	FOR(i,1,10010) {
		REP(j,i) {
			if(j%2==i%2) ber[i]-=((fac[i+1]*revfac[i+1-j])%MOD*revfac[j])%MOD*ber[j];
			else ber[i]+=((fac[i+1]*revfac[i+1-j])%MOD*revfac[j])%MOD*ber[j];
			ber[i]%=MOD;
		}
		ber[i]*=_pow(i+1,MOD-2);
		ber[i]%=MOD;
	}
	ll ans=0;
	REP(i,k+1) {
		ans+=(((_pow(n,(k+1)-i)*fac[k+1])%MOD*revfac[k+1-i])%MOD*revfac[i])%MOD*ber[i];
		ans%=MOD;
	}
	ans*=_pow(k+1,MOD-2);
	ans%=MOD;
	ans*=revfac[10009];
	ans=(ans%MOD+MOD)%MOD;
	cout<<ans<<endl;
}
0