/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;
ll f[N], rf[N];
ll po(ll a, ll b){ll res = 1; while(b){if(b&1) (res*=a)%=MOD; b>>=1; (a*=a)%=MOD;} return res;}
void precalc(){
f[0] = 1;
for(ll i = 1; i < N; ++i) f[i] = (f[i - 1] * i) % MOD;
rf[N-1] = po(f[N-1], MOD-2);
for(ll i = N-2; i >= 0; --i) rf[i] = (rf[i + 1] * (i+1)) % MOD;
}
ll c(ll n, ll k){
if(n < k) return 0;
return (((f[n] * rf[k]) % MOD) * rf[n - k]) % MOD;
}
ll n, k;
void solve(){
precalc();
cin >> n >> k;
--k;
ll ans = 0;
for(int i = 0; i <= k; ++i){
if(i % 2){
ans -= c(n + 1, i) * (po(k + 1 - i, n)) % MOD;
} else{
ans += c(n + 1, i) * (po(k + 1 - i, n)) % MOD;
}
ans %= MOD;
}
cout << (ans+MOD)%MOD;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(tt--){
solve();
en;
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
# | 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... |