• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
June 10, 2022 |5.3K Views

Python Program to Check Prime Number

  Share   Like
Description
Discussion


In this video, we will learn how to find prime numbers using python. This video is divided into 5 sections to find prime numbers.

Below is the list of approaches that we will cover in this section:

1. What is prime number
2. Brute fore method to check prime number.
3. Optimal solution for finding prime number.
4. Code in python and its time complexity.
5. Prime number using Recursive method.

A prime number is a natural number greater than 1, which is only divisible by 1 and itself.

First few prime numbers are: 2 3 5 7 11 13 17 19 23. In other words, a number is prime if it is not divisible by any number from 2 to n-1.

In the first approach, we will see the brute force method which has the time complexity of O(N^2), and Space Complexity: O(1). 
Later we will optimize it and decrease its time complexity with O(N^(3/2)).

Program to print first n prime numbers: https://www.geeksforgeeks.org/program-to-print-first-n-prime-numbers/