#include <cstdio>
#include <algorithm>
#define ll long long
#define mod 1000000007
ll n,k,res,now=1,now2;
ll table2[100],table[2000010],stable[2000010];
void make_table(ll a){
int i;
table2[0]=a%mod;
for(i=1;i<32;i++) table2[i]=(table2[i-1]*table2[i-1])%mod;
}
ll pow(ll a,ll s){
ll i,now=1,res=1;
make_table(a);
for(i=0;s;i++){
if(s&now) res*=table2[i],res%=mod,s-=now; now*=2;
}
return res;
}
int main(){
int i;
scanf("%lld %lld",&n,&k); table[0]=1; stable[0]=1;
for(i=2;i<=2*n;i+=2){
table[i]=stable[i-2]; stable[i]=stable[i-2]+table[i]; stable[i]%=mod;
}
for(i=0;i<n;i++) now2*=k,now2%=mod;
for(i=0;i<=n;i++){
now2=pow(k,(n-i)/2);
res+=(((table[n-i]*now2)%mod)*now)%mod; now*=k; now%=mod; res%=mod;
}
printf("%lld",res);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
106 ms |
32332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |