Submission #19736

# Submission time Handle Problem Language Result Execution time Memory
19736 2016-02-25T05:06:44 Z myungwoo 괄호 (kriii4_R) C++14
0 / 100
511 ms 24544 KB
#include<stdio.h>
#define mod 1000000007
#define inv(a) exp(a,mod-2)

typedef long long lld;

lld exp(lld a, lld b){
	if(b==0)return 1;
	lld k=exp(a, b/2);
	k=(k*k)%mod;
	if(b%2)k=(k*a)%mod;
	return k;
}

lld fac[1001001], rfac[1001001];

void init(){
	lld i;
	fac[0]=rfac[0]=1;
	for(i=1; i<=1000000; i++){
		fac[i]=(fac[i-1]*i)%mod;
		rfac[i]=inv(fac[i]);
	}
}

lld comb(lld a, lld b){
	return fac[a]*rfac[b]%mod*rfac[a-b]%mod;
}

lld n, k, dy[1001001];

int main(){
	lld i;
	init();
	scanf("%lld%lld", &n, &k);
	dy[0]=1;
	for(i=1; i<=n; i++){
		dy[i]=dy[i-1]*k%mod;
		if(i%2==0){
			lld j=i/2;
			lld cat=comb(i,j)*inv(j+1)%mod;
			cat=(cat*exp(k,j))%mod;
			dy[i] = (dy[i]+cat)%mod;
		}
	}
	printf("%lld", dy[n]);
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 511 ms 24544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -