You will list the divisors of a number, count them with the formula, add them, and test numbers for being perfect.
The idea. Divisors come in pairs and , so you only need to try up to . The formula needs only the exponents of the factorisation.
Your tasks.
divisors(n). Return the sorted list of all positive divisors of n. Try only d with d * d <= n, and add both d and n // d.tau_from_exponents(exponents). For a list of exponents such as [3, 2, 1], return the product of the numbers one more than each.is_perfect(n). Return True when the sum of the divisors of n is 2 * n.Run your code once to unlock the worked solution.
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…