SoFunction
Updated on 2024-11-15

Python solves for all prime numbers in any closed interval

Topic: Find all prime numbers in any interval [a,b], simple considerations for practicality

This question seems like it should be pretty easy, right, but arbitrary intervals (does this question get it)

Afanty's analysis:

1, first of all understand what is meant by prime number, note that the upper limit of the cycle judged by the remainder method should be sqrt(n), right?

2. Any interval, is a,b can be negative, decimal, etc..

So shouldn't we first round up the lower limit of the interval and round down the upper limit of the interval to get a new interval [a,b] before judging?

How can I tell?

case1: when b<0, is it not necessary to solve for

case2:when a<0,b>0,is it that a should start at 1 and the interval becomes [1,b]

case3:When a>0,b>0,is the interval still [a,b]?

Python's implementation of related functions

()

()

()