You will write three functions that explore two series. One of them is the harmonic series, which diverges slowly. The other is a telescoping series, whose partial sums have a simple closed form.
The idea. The harmonic partial sum is . The telescoping series has the partial sum , which you can check against a loop.
Your tasks.
harmonic(N). Return by adding 1 / n for n = 1, ..., N.telescoping(N). Return the sum of 1 / (n * (n + 1)) for n = 1, ..., N by a loop.first_above(target). Return the smallest N for which harmonic(N) is greater than target.Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…