A Squared Recurrence Relation

The function $f$ is defined for all positive integers as follows:
\begin{align*}
f(1) &= 1\\
f(2n) &= 2f(n)\\
f(2n+1) &= 2n+1 + 2f(n)+\tfrac 1n f(n)
\end{align*}
It can be proven that $f(n)$ is integer for all values of $n$.
The function $S(n)$ is defined as $S(n) = \displaystyle \sum_{i=1}^n f(i) ^2$.
For example, $S(10)=1530$ and $S(10^2)=4798445$.
Find $S(10^{16})$. Give your answer modulo $1\,000\,000\,007$.

This problem requires a deep understanding of writing recursive functions as well as modular arithmetic. Here is a step by step solution:

Firstly, notice that this is a recursion problem.

Recursion in math is when the output value of a function is used as an input for future computations.

The given recursive function $f(n)$ is based on whether $n$ is an odd or even number.

Specifically, the function is defined as:

$f(1) = 1$

$f(2n) = 2f(n)$

$f(2n+1) = 2n+1 + 2f(n)+\tfrac 1n f(n)$

As given $f(n)$ is integer for all values of $n$, this means all results yielded from the recursive function are whole numbers.

The function $S(n)$ is defined as the summation from $i = 1$ to $n$ of $f(i)$ squared.

The problem is asking to find $S(10^{16})$ modulo $1,000,000,007$.

We need to infer two things from the given recursion:

1. $f(2n)$ is even because it’s $2$ times some integer.
2. $f(2n+1)$ is odd because adding an odd integer and an even integer results in an odd number.

Noticing this pattern, we can tell that every odd-th term is odd.

We’re trying to compute $S(n) = f(1)^2 + f(2)^2 + f(3)^2 + … + f(n)^2$, and we see how the odd and even terms separately contribute to the answer.

Even-indexed terms f(2), f(4), …, f(2n) are all even, so their squares are multiples of $4$, and in mod $1000000007$, they’re multiples of $4$.

Odd indexed terms f(1), f(3), …, f(2n – 1) are all odd, so their squares are $1$ mod $4$, and in mod $1000000007$, they’re $1 \mod{4}$.

Let E(n) denote $f(2)^2 + f(4)^2 + … + f(2n)^2$, and O(n) to be $f(1)^2 + f(3)^2 + … + f(2n – 1)^2$.

Then, we need to compute $E(10^{16}) + O(10^{16})$ mod $1000000007$. By the above observations, $E(10^{16})$ is divisible by 4 and $O(10^{16})$ has a remainder of $10^{16}$ when divided by 4.

So, $S(10^{16}) = E(10^{16}) + O(10^{16}) \equiv 0 + 10^{16} \equiv 10^{16} \mod{4}$.

Therefore, we need to compute $10^{16} \mod{1000000007}$.

Now, by Euler’s theorem, $10^{phi(1000000007)} = 10^{1000000006} \mod{1000000007} = 1$.

Note: Euler’s theorem states that if ‘a’ and ‘n’ are coprime positive integers, then $a^{\phi(n)} = 1$ (mod n), where phi(n) is Euler’s totient function.

Hence, using the theorem $10^{16} = 10^{15 * 1000000006 + 6} = 10^{6} = 1000000$.

Therefore, the answer is $S(10^{16}) \equiv 1000000 \mod{1000000007}$.

More Answers:
Not Zeckendorf
Stealthy Numbers
Buckets of Water

Error 403 The request cannot be completed because you have exceeded your quota. : quotaExceeded

Share:

Recent Posts