Years back, I encountered the following problem in a book on Number Theory:
Prove that the sum
Even though I had some vague ideas for a proof, it took me quite a long time to actually prove the statement. Of course, this has more to do with my own inability than with the hardness of the problem itself. As it turns out, the problem is not that difficult.
First of all, let us understand that when the problem talks about integers, it
means real, exact integers. Not approximations like
Let us also remind ourselves that in order for two simplified fractions (where the numerator and the denominator have no common factors other than 1) to add up to an integer, both should have the same denominator. Convince yourself that this is indeed the case.
It always helps to see some examples to get an idea about what we need to prove. We can manually compute the fractions, but why bother, when we can write a script to do it? The good thing is that Python comes with a library called fractions for manipulating rational numbers, so we don’t have to worry about writing code for adding or simplifying fractions. Here is the function:
from fractions import Fraction
def harmonic(n):
s = 0
sum_fs = []
for i in range(1, n+1):
s += Fraction(1, i)
sum_fs.append(s)
return sum_fs
When called with
So what can we infer from the first five Harmonic numbers? The denominators
appear to be increasing. In fact they seem to be increasing much faster than the
natural numbers. Could we utilize this property to prove the claim? If we could
show that the denominators are monotonously increasing, and that they are
increasing at a higher rate than the indices
Darn! The denominators are not monotonously increasing! That’s a shame. What can we do? Should we scrap the whole idea or can we use it in another way? Maybe there is something about the denominators that is monotonously increasing, even though the denominators themselves are not. Let us take a break and think about it!
OK, the idea that seems to work is related to the great little number
def max_power_two(n):
s = 1
while n % 2 == 0:
s *= 2
n //= 2
return s
That //, btw, is the Python 3 integer division operator (as opposed to /, the floating point division operator).
Using the following snippet, we can compute the largest power of
[max_power_two(fr.denominator) for fr in harmonic(10)]
And the numbers are
Here is an informal argument as to why this trend holds up. Let us take the
concrete example of
Note that the numerator is still odd, and the denominator still contains exactly
By the same argument,
You probably see the pattern now. Since
For confirmation, let us see a graph of

As expected, the graph is a nice step function.
As a more powerful check, we can automatically verify, for a large number of
integers
def harmonic_power_two_check(n):
max_twos = [max_power_two(fr.denominator) for fr in harmonic(n)]
cur_power_two = 2
last_i = 1
while cur_power_two <= n:
for i in range(last_i, cur_power_two):
if max_twos[i-1] > cur_power_two:
print("Your proof is bunkum! Counter example at i = {0}, s = {1}".format(i, cur_power_two))
return
last_i = cur_power_two
cur_power_two *= 2
print("No counter-example found!")
The code basically checks that the denominators of all harmonic numbers from
No counter-example found!
Whew! That’s a relief!