# Golomb sequence

How to compute $n$-th element in golomb's sequence? I've found that $A_n$ is approximately: $$\phi^{2-\phi} * n^{\phi-1},\;\; \text{ where }\;\; \phi \;\;\text {is golden ratio}.$$

As far as I checked with my python and C++ program it gives right answers for low numbers, but for high numbers like $10^9$ or $10^{18}$ it's totally wrong.

Is there another solution without computing so many numbers (even to $10^{18}$)?

Chris

-
You are probably overflowing... –  soandos Jun 12 '11 at 22:00
According to A001462 $a(n)=\varphi ^{2-\varphi }n^{\varphi -1}+E(n)$, where $E(n)$ is $O(n^{\varphi -1}/\log n)$. This means that $\frac{a(n)}{\varphi ^{2-\varphi }n^{\varphi -1}}=1+O\left( \frac{% 1}{\log n}\right) \rightarrow 1$. –  Américo Tavares Jun 12 '11 at 22:23
For a definition of Golomb sequence and the asymptotics mentioned in the post, en.wikipedia.org/wiki/Golomb_sequence –  Did Jun 13 '11 at 7:57
python easily handle big ints, so i don't think this is the reason. Difference between big numbers as 10^9 is ~100. –  Chris Jun 13 '11 at 14:46