結果

問題 No.665 Bernoulli Bernoulli
ユーザー tecchaxntecchaxn
提出日時 2018-03-13 19:09:12
言語 C++11
(gcc 11.4.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,144 bytes
コンパイル時間 1,548 ms
コンパイル使用メモリ 145,756 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-14 16:01:14
合計ジャッジ時間 5,835 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘long long int init()’:
main.cpp:21:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^

ソースコード

diff #

#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;

//-----------------------------------------------------------------------

const int mod=1e9+7;
const int N=10010;
int fact[N],finv[N],inv[N];

int init()
{
    fact[0]=fact[1]=finv[0]=finv[1]=inv[1]=1;
    for(int i=2;i<N;i++){
	inv[i]=inv[mod%i]*(mod-mod/i)%mod;
	fact[i]=(fact[i-1]*i)%mod;
	finv[i]=(finv[i-1]*inv[i])%mod;
    }
}
int comb(int n,int k)
{
    if(k<0 or n<k) return 0;
    return fact[n]*finv[k]%mod*finv[n-k]%mod;
}

int mod_pow(int x,int n)
{
    int res=1;
    while(n>0){
	if(n&1) res=res*x%mod;
	x=x*x%mod; n>>=1;
    }
    return res;
}

signed main()
{
    init();
    int N,K; cin>>N>>K;
    vector<int> b(K+1,1);
    for(int i=1;i<=K;i++){
	int sum=0;
	for(int j=0;j<i;j++){
	    int tmp=b[j]*comb(i+1,j);
	    if(j&1) tmp=mod-tmp;
	    sum=(sum+tmp)%mod;
	}
	if(!(i&1)) sum=mod-sum;
	b[i]=sum*inv[i+1]%mod;
    }

    int ans=0;
    for(int i=0;i<=K;i++){
	int tmp=comb(K+1,i)*b[i]%mod*mod_pow(N%mod,K+1-i);
	ans=(ans+tmp)%mod;
    }
    cout<<ans*inv[K+1]%mod<<endl;

}
0