You are currently viewing Python Program for Find largest prime factors of a number in python
Python Program For Find Largest Prime Factors Of A Number In Python

Python Program for Find largest prime factors of a number in python

Spread the love

Factors are numbers which completely divide one number to become remainder as zero.

Python Program For Find Largest Prime Factors Of A Number In Python
Python Program For Find Largest Prime Factors Of A Number In Python

Prime numbers are which is divisible by itself and one .

Ex: if we take 10 the factors of 10 is 2,3,5,10 among this prime factors are 2,3,5. Among these 3 numbers 5 is the greatest number so here 5 is the largest prime factor of 10.

So the steps are first need to find the factor of given number and check those are also prime number and finally choose the largest number from the prime factor.

 First create the function called largestPrimeFactor and assign prime factor as 1 and i as 2 

def LargestPrimeFactor(n):

    primeFactor = 1

    i = 2

then looping statement to check prime number while diving n by i it should be greater than n then it will enter into loop then check for condition n%i =0 if that is true primefactor will be updated from 1 to i then n becomes n/i if that condition fails i should increase by 1 finally check for largest prime factor

while i <= n / i:

        if n % i == 0:

            primeFactor = i

            n = n/i

        else:

            i = i+1

    if primeFactor < n:

        primeFactor = n

    return primeFactor

then get input from the user and call the function for that number (Driver code)

num=int(input("Enter the test number:"))

print(LargestPrimeFactor(num))

Name of intern who share this Task :

K.Kathir oli
2nd year B.tech Cse

github link : https://github.com/Kathiroli9602/Tasks/tree/main

sachin Pagar

I am Mr. Sachin pagar Embedded software engineer, the founder of Sach Educational Support(Pythonslearning), a Passionate Educational Blogger and Author, who love to share the informative content on educational resources.

Leave a Reply