Python Nozioni di baseFacile

Numero primo entro un dato intervallo

Guida dettagliata e implementazione Python per il problema "Numeri primi entro un dato intervallo".

Dichiarazione del problema

Facile

Scrivi una funzione primes_in_range(a, b) che accetta due numeri interi a e b (dove a <= b) e restituisce un elenco di tutti i numeri primi nell'intervallo [a, b] compreso, in ordine crescente.

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

Esempi

Example 1
Input
a = 10, b = 30
Output
[11, 13, 17, 19, 23, 29]
Explanation

The prime numbers between 10 and 30 are 11, 13, 17, 19, 23, and 29.

Example 2
Input
a = 1, b = 10
Output
[2, 3, 5, 7]
Explanation

The prime numbers between 1 and 10 are 2, 3, 5, and 7.

Example 3
Input
a = 4, b = 4
Output
[]
Explanation

4 is not prime, so the result is an empty list.

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.