結果

問題 No.665 Bernoulli Bernoulli
ユーザー polylogKpolylogK
提出日時 2018-03-09 23:16:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 369 ms / 2,000 ms
コード長 2,193 bytes
コンパイル時間 1,863 ms
コンパイル使用メモリ 164,748 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 02:30:29
合計ジャッジ時間 8,200 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 4 ms
5,376 KB
testcase_02 AC 369 ms
5,376 KB
testcase_03 AC 366 ms
5,376 KB
testcase_04 AC 337 ms
5,376 KB
testcase_05 AC 323 ms
5,376 KB
testcase_06 AC 311 ms
5,376 KB
testcase_07 AC 301 ms
5,376 KB
testcase_08 AC 306 ms
5,376 KB
testcase_09 AC 343 ms
5,376 KB
testcase_10 AC 309 ms
5,376 KB
testcase_11 AC 357 ms
5,376 KB
testcase_12 AC 345 ms
5,376 KB
testcase_13 AC 358 ms
5,376 KB
testcase_14 AC 364 ms
5,376 KB
testcase_15 AC 318 ms
5,376 KB
testcase_16 AC 325 ms
5,376 KB
testcase_17 AC 314 ms
5,376 KB
testcase_18 AC 302 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define pq priority_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
using namespace std;
typedef long long ll; typedef long double ld;
constexpr long long gcd(long long a, long long b){return b ? gcd(b, a % b) : a;}
constexpr long long lcm(long long a, long long b){return a / gcd(a, b) * b;}
constexpr int INF = 1e9, MOD = INF + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
constexpr int mod_pow(long long x, long long n, const int mod){long long ret=1;while(n){if(n&1)(ret*=x)%=mod;(x*=x)%=mod;n>>=1;}return ret;}
template<int n> struct Prime{bool arr[n+1];constexpr bool operator[](int k){return arr[k];}constexpr Prime():arr(){for(int i=2;i<n;i++){arr[i]=true;for(int j=2;j*j<=i;j++){if(!(i%j))arr[i]=false;}}}};
template<int n> struct Factorial{long long arr[n+1],ary[n+1];constexpr Factorial():arr(),ary(){arr[0]=1;ary[0]=1;for(int i=0;i<n;i++){arr[i+1]=arr[i]*(i+1)%MOD;ary[i+1]=mod_pow(arr[i+1],MOD-2,MOD);}}};
//constexpr Factorial<10> fact;
constexpr Prime<10> prime;
//constexpr int comb(int a, int b){long long pos = fact.arr[a], pot = fact.ary[a - b], por = fact.ary[b];return pos * pot % MOD * por % MOD;}
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
constexpr int sqrtN = 512, logN = 32;
constexpr ld PI = abs(acos(-1));
constexpr ll LINF=1e18;

ll b[10010], fact[10010], inv[10010];

void make(int n){
	fact[0] = inv[0] = 1;
	for(int i = 0; i < n; i++) fact[i + 1] = fact[i] * (i + 1) % MOD;
	for(int i = 0; i < n; i++) inv[i + 1] = mod_pow(fact[i + 1], MOD - 2, MOD);
}

ll comb(int a, int b){
	ll p = fact[a];
	ll q = inv[a - b];
	ll r = inv[b];
	
	return p * q % MOD * r % MOD;
}

int main(){
	ll n, k; cin >> n >> k;
	make(10010);
	
	b[0] = 1;
	for(int i = 1; i <= k + 1; i++){
		ll pos = 0;
		for(int j = 0; j < i; j++){
			(pos += comb(i + 1, j) * b[j] % MOD) %= MOD;
		}
		
		b[i] = (MOD - mod_pow(i + 1, MOD - 2, MOD)) % MOD * pos % MOD;
	}
	
	ll ans = 0; n++;
	for(int j = 0; j <= k; j++){
		ll p = comb(k + 1, j);
		ll q = b[j];
		ll r = mod_pow(n % MOD, k + 1 - j, MOD);
		
		(ans += p * q % MOD * r % MOD) %= MOD;
	}
	
	cout << ans * mod_pow(k + 1, MOD - 2, MOD) % MOD << endl;
	return 0;
}
0