Python program to find smallest prime divisor of a number

In this tutorial, we will learn how to get the smallest prime divisor or we can say the smallest divisor of a number in Python program.

There are some steps given below for finding the smallest prime divisor for a number you want to get. The prime divisor is a non-constant integer that is divisible by the prime and is called the prime divisor of the polynomial.

There are few prime divisors like : 2 , 3 , 5 ,7 , 11 ,13 ,17 ,19 and 23.

Divisors can be positive as well as they can be negative also. An integer and its negation is also a divisor.


1. Get the input from the user. the input will be in the form of an integer.

2. Select the range of numbers for the input digits.
3. Then select the list of the divisor for the input digits.

4. Use the if condition.
5. Then print the list.
6.after printing the list you have to do indexing for the smallest prime divisor from the list of divisors.

for example:-

Python program for getting the smallest divisor of a number

X = int(input("enter any digit"))
DivisorRange = range(2 , X+1)

list = [ i for i in DivisorRange if X%i==0]


#for getting the smallest prime divisor
Input : 50

Output : [2, 5, 10, 25, 50]

#Final Output after indexing

Output : 2

from the above example, you will get to know how to get the smallest divisor from all the number of divisors we get in the output.

Also read:

Leave a Reply

Your email address will not be published. Required fields are marked *