Possible Duplicate:
I want to generate the nth term of the sequence 1,3,8,22,60 ,164 in Order(1) or order of (nlogn)
What I do now is:
t1 = 1, t2 = 0,MOD = 1000000007;
for i = 1:n
t1_new = (2*(t1+t2)) % MOD;
t2_new = t1;
a[i] = (t1_new + t2_new) % MOD; // where a[i] is the ith term mod p
t1 = t1_new;
t2 = t2_new;
return a[n]; // the required ans
But it is an O(n) solution.
Please give me only hints(no solution please) so that I can reduce the complexity of the solution.