Perfect numbers P34091


Statement
 

pdf   zip   main.cc   main.c   main.java   main.py

thehtml

Write a function that tells if a natural n is perfect.

A natural number is called perfect if it is equal to the sum of all its divisors except itself. For instance, 28 is perfect, because 28=1+2+4+7+14.

Interface

C++
bool is_perfect(int n);
C
int is_perfect(int n);
Java
public static boolean isPerfect(int n);
Python
is_perfect(n) # returns bool
 
is_perfect(n: int) -> bool

Precondition

n is a natural number.

Observation You only need to submit the required procedure; your main program will be ignored.

Public test cases
  • Input/Output

    is_perfect(28) → true
    is_perfect(1) → false
    is_perfect(100) → false
    is_perfect(0) → false
  • Information
    Author
    Jordi Petit
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C C++ Java Python
    User solutions
    C C++ Java Python