2

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.

  • Forgive me if I'm not seeing something, but haven't you already proven the claim through strong induction? Base case is good, then assume it is true for all $n< N$ and prove it for $N$ – QC_QAOA Jan 21 '25 at 03:07
  • 1
    I can't speak for the OP, but I would be rather annoyed by @Alwaz's pointless edits! – TonyK Jan 21 '25 at 03:22
  • @TonyK OP here, Rex Nolan pointed a mistake in my evaluations, which is so funny because he should have changed that lmfao – ducbadatcs Jan 21 '25 at 08:04
  • I did not see your mistake till you wrote it out in the comments. Though I am not in the business of editing posts so would not have anyways, even if I did see it. I will remove my "answer". – Rex Nolan Jan 21 '25 at 14:58

1 Answers1

2

Both OP and Rex Nolan found that $$\begin{aligned} s_{2n} &= s_n\\ s_{2n+1} &= 1 + s_n \end{aligned}$$ so that $s_n$ and $f(n)=ns_n$ are integer sequences, by strong induction. Furthermore, we observe that $$s_n=n-\sum_{i=1}^\infty\left\lfloor\frac{n}{2^i}\right\rfloor$$ is the sum of binary digits of $n$. You may see this related answer.

Alwaz
  • 155
Bob Dobbs
  • 15,712