Interesting homework. You can solve it without using a loop. It is just a mathematical problem. The solution is quite simple so I believe you can solve it alone.