How to Find the Smallest Divisor of an Integer in Python


In this example we will show the methods to find the minimum divisible number of integers in Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

n = int(input("Enter an integer: "))
for i in range(2, n + 1):
    if n % i == 0:
        print("Smallest divisor is:", i)
        break

Output:

Enter an integer: 25
Smallest divisor is: 5

Enter an integer: 24
Smallest divisor is: 2
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments