Python Nozioni di baseFacile

Numero di Armstrong in un dato intervallo

Guida dettagliata e implementazione Python per il problema "Numero di Armstrong in un dato intervallo".

Dichiarazione del problema

Facile

Scrivi una funzione armstrongs_in_range(a, b) che accetta due numeri interi a e b (dove a <= b) e restituisce un elenco di tutti i numeri Armstrong nell'intervallo [a, b] compreso, in ordine crescente. Un numero Armstrong è un numero uguale alla somma delle sue cifre, ciascuna elevata alla potenza del numero di cifre.

Vincoli
  • 1 <= a <= b <= 10^5

Esempi

Example 1
Input
a = 100, b = 500
Output
[153, 370, 371, 407]
Explanation

The Armstrong numbers between 100 and 500 are 153, 370, 371, and 407.

Example 2
Input
a = 1, b = 9
Output
[1, 2, 3, 4, 5, 6, 7, 8, 9]
Explanation

All single-digit numbers are Armstrong numbers since d^1 = d.

Example 3
Input
a = 200, b = 300
Output
[]
Explanation

There are no Armstrong numbers between 200 and 300.

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.