Submission #20155

# Submission time Handle Problem Language Result Execution time Memory
20155 2016-02-28T16:49:25 Z tonyjjw 괄호 (kriii4_R) C++14
0 / 100
88 ms 16904 KB
//*
#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,int 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(K,N-i);
        v%=mod;
        ans+=v;
        ans%=mod;
    }
    if(ans<0)ans+=mod;
    printf("%lld\n",ans);
    return 0;
}
//*/
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 16904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -