Using Python to Find Prime Numbers
What's a prime number? A prime number is a natural number that's only divisible by 1 and itself. Also, a composite number is a natural number with positive factors other than 1 and itself. Thus, we can conclude that a prime number is not a composite number by the definitions. There are many algorithms to find prime numbers. First, we will introduce the simplest way to find prime numbers. Determining whether a number is prime or not is not really very different from determining whether a number is composite or not. To determine whether a number is composite, it is by definition sufficient to find a factor other than 1 and itself. If we find such a factor m for a number n, i.e. m divides n, then we must have m < n. So we only need to find a factor of n in the range from 2 to n-1. Here is the code: However, this brute force algorithm will take a lot of time to find the prime numbers if the range is too large. There is a better algorithm to save the time. In ancient Greece, a ma...