3 ms·
Indeed! I was trying in Julia and got [0, 1, 1, 2, 3, 5, 8, 0, 0, 0]. Had to use "big integers" to make it work past n=7: function f(n) b = big(2) << n
by cbolton 3y ago
Indeed! I was trying in Julia and got [0, 1, 1, 2, 3, 5, 8, 0, 0, 0]. Had to use "big integers" to make it work past n=7:
function f(n)
b = big(2) << n
return b^(n+1) ÷ (b^2-b-1) % b
end
or for code golf:
f(n;b=big(2)<<n)=b^(n+1)÷(b^2-b-1)%b
With "big" f.(1:10) gives the expected answer.