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 ll long long
#define ld long double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e5 + 9;
const ll mod = 1e9 + 7;
const ll base = 31;
ll n,k,fac[N],ans,sum;
ll bpow(ll a,ll b){
ll res = 1;
while(b){
if (b & 1) res = (res*a)%mod;
a = (a*a)%mod; b >>= 1;
}
return res;
}
ll C(ll k,ll n){
ll ts = fac[n],ms = fac[k] * fac[n - k]; ms %= mod;
return (ts * bpow(ms,mod - 2))%mod;
}
int main(){
ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define task "tst"
if (fopen(task".inp","r")){
freopen(task".inp","r",stdin);
//freopen(task".out","w",stdout);
}
cin>>n>>k; fac[0] = 1;
for (ll i = 1;i < N;i++) fac[i] = (fac[i - 1] * i)%mod; //debug(C(2,4));
for (ll i = 0;i <= k;i++){
sum = (bpow(k - i,n) * C(i, n+1)) % mod; //debug(C(i,n + 1));
if(i&1) ans = (ans - sum + mod) % mod;
else ans = (ans + sum) % mod;
}
debug(ans);
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
Compilation message (stderr)
asceticism.cpp: In function 'int main()':
asceticism.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |