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;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <ext/rope>
using namespace __gnu_cxx;
typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements
//#define DEBUG
#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__);
#else
#define debug(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
#define mod 1000000007
int n,k;
ll fac[100005],ifac[100005];
ll pwr(int x,int p){
if(p==0)return 1;
ll t=pwr(x,p/2);
ll r=(t*t)%mod;
if(p%2)r*=x,r%=mod;
return r;
}
int main(){
sf("%d%d",&n,&k);k=n-k;
fac[0]=1;for(int i=1;i<=n+1;++i)fac[i]=(fac[i-1]*i)%mod;
for(int i=0;i<=n+1;++i)ifac[i]=pwr(fac[i],mod-2);
ll res=0;
for(int i=0;i<=k+1;++i){
ll a=(((fac[n+1]*ifac[i])%mod)*ifac[n+1-i])%mod;
ll b=pwr(k+1-i,n);
if(i%2==0)res+=a*b,res%=mod;
else res+=mod-a*b,res%=mod;
}
pf("%lld\n",res);
}
//lol https://en.wikipedia.org/wiki/Eulerian_number
Compilation message (stderr)
asceticism.cpp: In function 'int main()':
asceticism.cpp:55:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
55 | sf("%d%d",&n,&k);k=n-k;
| ^
# | 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... |