Python Nozioni di baseFacile

Numero di Armstrong

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

Dichiarazione del problema

Facile

Scrivi una funzione is_armstrong(n) che accetta un intero positivo n e restituisce True se è un numero di Armstrong, o False altrimenti. Un numero Armstrong (numero narcisistico) è un numero che equivale alla somma delle proprie cifre, ciascuna elevata alla potenza del numero di cifre. Ad esempio, 153 ha 3 cifre e 1^3 + 5^3 + 3^3 = 153.

Vincoli
  • 1 <= n <= 10^6

Esempi

Example 1
Input
n = 153
Output
True
Explanation

153 has 3 digits. 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153. So it is an Armstrong number.

Example 2
Input
n = 370
Output
True
Explanation

370 has 3 digits. 3^3 + 7^3 + 0^3 = 27 + 343 + 0 = 370.

Example 3
Input
n = 123
Output
False
Explanation

123 has 3 digits. 1^3 + 2^3 + 3^3 = 1 + 8 + 27 = 36, which is not 123.

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.