I am interested in problem 759 in Project Euler.
For those who don’t know, here’s the problem statement:
The function $f$ is defined for all integers as follows: $$\begin{align} f(1) &= 1 \\ f(2n) &= 2f(n) \\ f(2n + 1) &= 2n + 1 + 2f(n) + \frac{1}{n}f(n) \end{align}$$ It can be proven that $f(n)$ is integer for all values of $n$ (here they meant integer $n$, I assume).
Define $\displaystyle{S(x) = \sum_{i=1}^n f(i)^2}$. Evaluate $S\left(10^{16}\right) \mod 10^9 + 7$.
I am interested in the claim that $f(i)$ is integer for all $i$ (and a potential solution if applicable). First, I noticed that $$f(2n + 1) = 2n + 1 + \frac{(2n + 1)}{n}f(n) = (2n + 1)\left(1 + \frac{f(n)}{n}\right)$$.
Since there's a fraction $\displaystyle{\frac{1}{n}f(n)}$, I decided to define a sequence $\displaystyle{s(n) = \frac{f(n)}{n}}$. Then, I noted that:
$$ \displaystyle{ s(1) = 1 \text{ by definition} \\ s(2n) = \frac{f(2n)}{2n} = \frac{2f(n)}{2n} = \frac{f(n)}{n} = s(n) \\ s(2n + 1) = \frac{f(2n + 1)}{2n + 1} = \frac{(2n + 1)\left(1 + \frac{f(n)}{n}\right)}{2n + 1} = \left(1 + \frac{f(n)}{n}\right) = 1 + s(n) } $$
I decided to write a Python program to compute some first few entries of $s(n)$, and I noted that all the $s(n)$ are integer. Since the output is long, I won't put it here.
n = 1000
f = [0 for i in range(n)]
f[1] = 1
for i in range(1, 1000):
if i == 1: f[i] = 1
elif i % 2 == 0:
f[i] = 2 * f[i // 2]
elif i % 2 == 1:
z = i // 2
f[i] = (2z + 1) f[z] * (z + 1) // z
print(i, f[i] // i)
It seems the $s(n)$ grows in an extremely irregular pattern, AND I can't prove that they too are integers. Any ideas?
Edit: mistakes when evaluating certain expressions.