#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define Mp make_pair
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input19.txt" , "r" , stdin) ;
const ll mod=1e9+7;
const int N = 1e5+23;
ll fact[N], inv[N];
int n, k;
ll power(ll a, ll b){
ll ans=1;
while(b){
if(b&1) ans=ans*a%mod;
b>>=1;
a=a*a%mod;
}
return ans;
}
ll C(ll r, ll n){
if(r>n || r<0) return 0;
return fact[n]*inv[r]%mod*inv[n-r]%mod;
}
int main()
{
fast_io
cin>>n>>k;
fact[0]=1;
for (int i=1; i<N; i++) fact[i]=fact[i-1]*i%mod;
inv[N-1]=power(fact[N-1], mod-2);
for (int i=N-2; i>=0; i--) inv[i]=inv[i+1]*(i+1)%mod;
ll ans=0;
for(int i=0; i<k; i++){
if(i&1) ans=(ans-C(i, n+1)*power(k-i, n)%mod+mod)%mod;
else ans=(ans+C(i, n+1)*power(k-i, n)%mod)%mod;
}
cout<<ans<<endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |