Python Nozioni di baseFacile

Numero forte

Guida dettagliata e implementazione Python per il problema dei "numeri forti".

Dichiarazione del problema

Facile

Scrivi una funzione is_strong(n) che accetta un intero positivo n e restituisce True se è un numero forte, o False altrimenti. Un numero forte è un numero in cui la somma dei fattoriali delle sue singole cifre è uguale al numero stesso. Ad esempio, 145 = 1! +4! +5! = 1 + 24 + 120 = 145.

Vincoli
  • 1 <= n <= 10^6

Esempi

Example 1
Input
n = 145
Output
True
Explanation

1! + 4! + 5! = 1 + 24 + 120 = 145, which equals n.

Example 2
Input
n = 2
Output
True
Explanation

2! = 2, which equals n.

Example 3
Input
n = 123
Output
False
Explanation

1! + 2! + 3! = 1 + 2 + 6 = 9, 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.