This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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*now; now*=k; now%=mod; res%=mod;
}
printf("%lld",res);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |