Submission #20156

#TimeUsernameProblemLanguageResultExecution timeMemory
20156tonyjjw괄호 (kriii4_R)C++14
100 / 100
354 ms16708 KiB
//* #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<algorithm> #include<vector> #define all(A) (A).begin(), (A).end() using namespace std; typedef long long ll; typedef pair<int,int> pii; const int MN = 1000000+10; const ll mod = 1000000007; ll fact[MN]; ll inv[MN]; ll pow(ll a,ll p){ ll r=1; while(p>0){ if(p&1)r=r*a%mod; a=a*a%mod; p>>=1; } return r; } ll comb(ll n,ll r){ return fact[n]*inv[r]%mod*inv[n-r]%mod; } ll inverse(ll a){ return pow(a,mod-2); } int main(){ int N,K; scanf("%d%d",&N,&K); fact[0]=1; for(int i=1;i<MN;i++){ fact[i]=fact[i-1]*i%mod; } for(int i=0;i<MN;i++){ inv[i]=inverse(fact[i]); } ll ans=0; for(int i=0;2*i<=N;i++){ ll v; if(i==0){ v=1; } else{ v=comb(N,i)-comb(N,i-1); } v*=pow((ll)K,(ll)N-i); v%=mod; ans+=v; ans%=mod; } if(ans<0)ans+=mod; printf("%lld\n",ans); return 0; } //*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...