This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e5+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll f[maxN],fr[maxN];
ll pw(ll x,ll y)
{
if(y==0) return 1;
ll x1=pw(x,y/2);
x1=x1*x1%mod;
if(y&1) x1=x1*x%mod;
return x1;
}
ll C(ll x,ll y)
{
return f[x]*fr[x-y]%mod*fr[y]%mod;
}
ll n,k,ans=0;
void solve()
{
cin >> n >> k;
f[0]=1;
k--;
for(int i=1;i<=2*n;i++)
{
f[i]=f[i-1]*i%mod;
}
fr[2*n]=pw(f[2*n],mod-2);
for(int i=2*n-1;i>=0;i--)
{
fr[i]=fr[i+1]*(i+1)%mod;
}
for(int j=0;j<=k+1;j++)
{
ll sig=1;
if(j%2) sig=-1;
ans+=sig*C(n+1,j)%mod*pw(k-j+1,n)%mod;
ans%=mod;
}
if(ans<0) ans+=mod;
cout << ans;
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
# | 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... |