重複の可能性:
Order(1) または (nlogn) の順序で、シーケンス 1,3,8,22,60 ,164 の n 番目の用語を生成したい
私が今していることは次のとおりです。
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
しかし、これは O(n) ソリューションです。
解決策の複雑さを軽減できるように、ヒントだけを教えてください(解決策はありません)。