結果

問題 No.665 Bernoulli Bernoulli
ユーザー gazellegazelle
提出日時 2018-03-11 04:04:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,479 bytes
コンパイル時間 894 ms
コンパイル使用メモリ 93,032 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 00:53:10
合計ジャッジ時間 1,580 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 6 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 6 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 6 ms
5,376 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 6 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 6 ms
5,376 KB
testcase_12 AC 6 ms
5,376 KB
testcase_13 AC 6 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 5 ms
5,376 KB
testcase_16 AC 6 ms
5,376 KB
testcase_17 AC 6 ms
5,376 KB
testcase_18 AC 6 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;
	}
}

ll A[10010];
ll N,K;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>N>>K;
	N%=MOD;
	ll sum=0;
	A[0]=0;
	FOR(i,1,K+2) {
		sum+=_pow(i,K);
		sum%=MOD;
		A[i]=sum;
	}
	if(N<=K+1) {
		cout<<A[N]<<endl;
		return 0;
	}
	ll ans=0;
	ll num=1;
	ll den=1;
	REP(i,K+2) {
		num*=N-i;
		num%=MOD;
	}
	REP(i,K+1) {
		den*=-(i+1);
		den%=MOD;
	}
	REP(i,K+2) {
		ll plus=(A[i]*num)%MOD;
		plus*=_pow(N-i,MOD-2);
		plus%=MOD;
		if(i) {
			den*=_pow(-(K+2-i),MOD-2);
			den%=MOD;
			den*=i;
			den%=MOD;
		}
		plus*=_pow(den,MOD-2);
		plus%=MOD;
		ans+=plus;
		ans%=MOD;
	}
	cout<<(ans%MOD+MOD)%MOD<<endl;
}
0