結果

問題 No.391 CODING WAR
ユーザー nxteru
提出日時 2018-10-29 23:01:25
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 534 bytes
コンパイル時間 1,537 ms
コンパイル使用メモリ 169,352 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-19 09:15:14
合計ジャッジ時間 2,532 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define M 1000000007
ll n,m,ans,k[100005],r[100005];
ll pw(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=res*a%M;
		b>>=1;
		a=a*a%M;
	}
	return res;
}
ll cm(ll a,ll b){
	return k[a]*r[b]%M*r[a-b]%M;
}
int main(void){
    cin>>n>>m;
    k[0]=1,r[0]=1;
    for(ll i=1;i<=m;i++){
		k[i]=k[i-1]*i%M;
		r[i]=pw(k[i],M-2);
	}
	ans=pw(m,n);
	for(ll i=1;i<=m;i++){
		if(i%2)ans=(ans+M-cm(m,i)*pw(m-i,n)%M)%M;
		else ans=(ans+cm(m,i)*pw(m-i,n)%M)%M;
	}
	cout<<ans<<endl;
}
0