Python Nozioni di baseFacile

Numero perfetto

Guida dettagliata e implementazione Python per il problema del "numero perfetto".

Dichiarazione del problema

Facile

Scrivi una funzione is_perfect(n) che accetta un intero positivo n e restituisce True se è un numero perfetto, o False altrimenti. Un numero perfetto è un numero uguale alla somma dei suoi divisori propri (tutti i divisori escluso il numero stesso). Ad esempio, 6 = 1 + 2 + 3.

Vincoli
  • 1 <= n <= 10^6

Esempi

Example 1
Input
n = 6
Output
True
Explanation

The proper divisors of 6 are 1, 2, 3. Their sum is 1 + 2 + 3 = 6.

Example 2
Input
n = 28
Output
True
Explanation

The proper divisors of 28 are 1, 2, 4, 7, 14. Their sum is 1 + 2 + 4 + 7 + 14 = 28.

Example 3
Input
n = 12
Output
False
Explanation

The proper divisors of 12 are 1, 2, 3, 4, 6. Their sum is 16, which is not 12.

Need a Hint?
Prendi in considerazione l'utilizzo di strutture dati specifiche di Basics come set o heap.
Edge Cases to Watch
  • Strutture di input vuote
  • Ingressi a elemento singolo
  • Grandi limiti numerici

Pronto a risolvere?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Apri nell'editor
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Risorse Python consigliate

Espandi le tue conoscenze con tutorial interattivi, foglietti illustrativi e confronti di codici correlati.