Perfect numbers

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+1428=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.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T10:20:25.770Z

© Jutge.org, 2006–2026.
https://jutge.org