$f(x,n)=x^{2^{1}}+x^{2^{2}}+x^{2^{3}}+...+x^{2^{n}}$
Example: $f(2,10)$ mod $1000000007$ = $180974681$
Calculate $\sum_{x=2}^{10^{7}} f(x,10^{18})$ mod $1000000007$.
We know that $a^{b^{c}}$ mod $p$ = $a^{b^{c} \hspace{0.5 mm} mod \hspace{1 mm} (p-1)}$ mod $p$.
So I tried to find the period of the sequence $2^n$ mod $1000000006$.
$\varphi(1000000006)=500000002$ is an integral multiple of this period. But I am stuck here. Any help please?
I verified that the period of the sequence $2^n$ mod $1000000006$ is indeed $500000002$.
Let $q=5000000003$ and $p=2q+1$
As $10^{18}=1999999992*(q-1)+16$, we have
$f(x,10^{18})=1999999992*(x^2+x^4+...+x^{2(q-1)})+(x^{2^{1}}+x^{2^{2}}+...+x^{2^{16}})$
Now we can use the fact that $2$ is a primitive root modulo $q$
$x^2+x^4+...+x^{2(q-1)}=x^2 \frac{x^{2(q-1)}-1}{x^2-1}\equiv -1$ mod $p$.
So we just have to compute $16*10^7$ values.