結果

問題 No.665 Bernoulli Bernoulli
ユーザー rickythetarickytheta
提出日時 2018-03-09 23:53:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 1,931 bytes
コンパイル時間 1,441 ms
コンパイル使用メモリ 159,472 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 04:21:16
合計ジャッジ時間 8,210 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 309 ms
5,248 KB
testcase_01 AC 314 ms
5,376 KB
testcase_02 AC 310 ms
5,376 KB
testcase_03 AC 307 ms
5,376 KB
testcase_04 AC 302 ms
5,376 KB
testcase_05 AC 306 ms
5,376 KB
testcase_06 AC 297 ms
5,376 KB
testcase_07 AC 299 ms
5,376 KB
testcase_08 AC 296 ms
5,376 KB
testcase_09 AC 307 ms
5,376 KB
testcase_10 AC 300 ms
5,376 KB
testcase_11 AC 297 ms
5,376 KB
testcase_12 AC 308 ms
5,376 KB
testcase_13 AC 293 ms
5,376 KB
testcase_14 AC 289 ms
5,376 KB
testcase_15 AC 292 ms
5,376 KB
testcase_16 AC 297 ms
5,376 KB
testcase_17 AC 309 ms
5,376 KB
testcase_18 AC 302 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

ll n,k;

ll modinv(ll a){
  ll b = MOD-2;
  ll r = 1;
  while(b){
    if(b&1)r=r*a%MOD;
    a=a*a%MOD;
    b>>=1;
  }
  return r;
}

ll modpow(ll a, ll b){
  ll r = 1;
  while(b){
    if(b&1)r=r*a%MOD;
    a=a*a%MOD;
    b>>=1;
  }
  return r;
}

ll fact[12525];
ll ifact[12525];

ll B[12525];

int main(){
  cin>>n>>k;

  fact[0] = 1;
  FOR(i,1,12525)fact[i] = fact[i-1]*i%MOD;
  REP(i,12525)ifact[i] = modinv(fact[i]);
  
  B[0] = 1;
  FOR(i,1,10025){
    ll tmp = 0;
    REP(k,i){
      ll binom = fact[i+1] * ifact[k] % MOD * ifact[i+1-k] % MOD;
      ll add = binom * B[k] % MOD;
      if(k%2==1){
        add = MOD - add;
      }
      tmp += add;
    }
    tmp = tmp % MOD * modinv(i+1) % MOD;
    if(i%2==0){
      tmp = (MOD - tmp) % MOD;
    }
    B[i] = tmp;
  }

  // REP(i,20)printf("fact : %lld\n", fact[i]);
  // REP(i,20)printf("B : %lld\n", B[i]);

  ll ans = 0;
  REP(j,k+1){
    ll binom = fact[k+1] * ifact[j] % MOD * ifact[k+1-j] % MOD;
    ans += binom * B[j] % MOD * modpow(n%MOD, k+1-j) % MOD;
  }
  ans = ans % MOD * modinv(k+1) % MOD;

  cout<<ans<<endl;
  return 0;
}
0