Programmazione competitivaFacile

Numeri brutti

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

Dichiarazione del problema

Facile

Scrivi una funzione nth_ugly_number(n) che restituisca il nesimo numero brutto. I numeri brutti sono numeri positivi i cui unici fattori primi sono 2, 3 o 5. Per convenzione, 1 viene trattato come un numero brutto.

Vincoli
  • 1 <= n <= 500

Esempi

Example 1
Input
nth_ugly_number(10)
Output
12
Explanation

The first 10 ugly numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12.

Example 2
Input
nth_ugly_number(15)
Output
24
Explanation

The first 15 ugly numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24.

Need a Hint?
Prendi in considerazione l'utilizzo di strutture dati specifiche della programmazione dinamica 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.