Submission #19707

# Submission time Handle Problem Language Result Execution time Memory
19707 2016-02-25T04:45:32 Z chan492811 괄호 (kriii4_R) C++
0 / 100
106 ms 32332 KB
#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;
}
# Verdict Execution time Memory Grader output
1 Incorrect 106 ms 32332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Halted 0 ms 0 KB -