Solving TD7 (finding perfect numbers between 1 and n)