No fraction has a square of exactly . But some come very close. For each bottom , take the top nearest to , and measure the miss . You will find the bottoms up to where the miss is only or .
The idea. If the miss were ever , then exactly, and would be rational.
Your tasks.
best_top, return the whole number nearest to q * sqrt(2).miss, return p * p - 2 * q * q, where p = best_top(q).close with the bottoms q from to whose miss is or , in order.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…