Simple python program to find Prime numbers (only 3 easy steps) | Latest Technology Updates

A prime number is a natural number greater than 1 and having no positive divisor other than 1 and itself.A factor is a whole numbers that can be divided evenly into another number. The first few prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23 and 29. Numbers that have more than two factors are called composite numbers. The number 1 is neither prime nor composite. For eg: 3, 7, 11,13 etc are prime numbers.

Composite number:

Other natural numbers that are not prime numbers are called composite numbers.
For eg: 4, 6, 9, 8 etc. are composite numbers.

Simple python program to find Prime numbers (only 3 easy steps) | Latest Technology Updates

How to determine if a number is prime

Various algorithms have been formulated in an attempt to generate ever-larger prime numbers. For example, suppose n is a whole number, and it is not yet known if n is prime or composite. First, take the square root (or the 1/2 power) of n; then round this number up to the next highest whole number and call the result m.

qm = n / m
q(m-1) = n / (m-1)
q(m-2) = n / (m-2)
q(m-3) = n / (m-3)
. . .
q3 = n / 3
q2 = n / 2

Let us discuss with a simple python program


number = int(input("Enter a numberber: "))

if number > 1:
   for i in range(2,number):
       if (number % i) == 0:
           print(number,"is not a prime number")
           print(i,"times",number//i,"is",number)
           break
   else:
       print(number,"is a prime number")
       
   else:
       print(number,"is not a prime number")  

Output-1

Prime_Number_Python_LatestTechUpdates



Output-2

Prime_Number_Python_LatestTechUpdates


Post a Comment

If you any doubts, Please let me know

Previous Post Next Post