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>
using namespace std ;
const int mod = 1e9 + 7 ;
int Add(int x , int y)
{
int z = x + y ;
if(z >= mod)
z -= mod ;
return z ;
}
int Sub(int x , int y)
{
int z = x - y ;
if(z < 0)
z += mod ;
return z ;
}
int Mul(int x , int y)
{
return (x * 1ll * y) % mod ;
}
int powlog(int base , int power)
{
if(power == 0)
return 1 ;
int x = powlog(base , power / 2) ;
x = Mul(x , x) ;
if(power & 1)
x = Mul(x , base) ;
return x ;
}
int modinv(int x)
{
return powlog(x , mod-2) ;
}
int Div(int x , int y)
{
return Mul(x , modinv(y)) ;
}
struct combination
{
vector<int>fact , inv ;
combination(int sz) : fact(sz + 1) , inv(sz + 1)
{
fact[0] = 1 ;
inv[0] = 1 ;
for(int i = 1 ; i <= sz ; ++i)
fact[i] = Mul(fact[i-1] , i) ;
inv[sz] = modinv(fact[sz]) ;
for(int i = sz-1 ; i >= 1 ; --i)
inv[i] = Mul(inv[i+1] , i+1) ;
}
int choose(int n , int k) const
{
if(k < 0 || n < k)
return 0 ;
return Mul(Mul(fact[n] , inv[k]) , inv[n - k]) ;
}
};
const int MAX = 1e5 + 10 ;
combination comb(MAX) ;
int arr[MAX] ;
int n , k ;
int main()
{
ios_base::sync_with_stdio(0) ;
cin.tie(0) ;
cin>>n>>k ;
k = n-k ;
int ans = 0 ;
for(int i = 0 ; i <= k ; ++i)
{
int x = Mul(comb.choose(n+1 , i) , powlog(k+1-i , n)) ;
if(i%2 == 0)
ans = Add(ans , x) ;
else
ans = Sub(ans , x) ;
}
return cout<<ans<<"\n" , 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... |