← Back to challenges

Weird Numbers

PythonHardnumbersmath

Instructions

A weird number is a natural number that is abundant but not semiperfect. An abundant number is a number for which the sum of its proper divisors is greater than the number itself. A positive divisor of n which is different from n is called a proper divisor of n. A semiperfect number is a natural number n that is equal to the sum of all or some of its proper divisors.

Objective

Create a function that takes a number as an argument and returns:

  • If the number is prime and not abundant.
  • If the number is not abundant.
  • If the number is abundant but not weird.
  • If the number is weird.

Examples

weird(1) ➞ "1 is not abundant because the sum of its proper divisors - no proper divisors - is 0."

weird(2) ➞ "2 is prime and not abundant."

weird(9) ➞ "9 is not abundant because the sum of its proper divisors 1, 3 is 4."

weird(12) ➞ "12 is abundant but not weird because it can be obtained from the sum of its proper divisors: 2, 4, 6."

weird(70) ➞ "70 is weird."

Notes

  • The number will always be greater than 0.
  • If the number is abundant, print the proper divisors with which you get the number, always running through the divisors from the smallest to the biggest, covering all possible combinations from the smallest possible lenght to the biggest possible lenght.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.