이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
#define M 1000000007ll
int n;
long long d[1000001],k,pow[1000001],comb[1000001];
int main()
{
int i;
scanf("%d%lld",&n,&k);
d[1] = k;
pow[0]=1ll;
for(i=1; i<=n; i++) pow[i] = (pow[i-1] * k) % M;
comb[1] = 2ll;
for(i=2; i<=n; i++) comb[i] = ((comb[i-1] / (long long)i) * (4ll*(long long)i - 2ll)) % M;
for(i=2; i<=n; i++){
if(i%2 == 0) d[i] = (d[i-1] * (k + 1ll)) % M;
else d[i] = (d[i-1] * (k + 1ll) - (pow[(i-1)/2] * comb[(i-1)/2] / (((long long)i-1ll)/2ll+1ll)) % M + M) % M;
}
printf("%lld\n",d[n]);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |