Python Program to Find Prime Factors of a Number


What is Prime Factorization?

Every natural number can be expressed as a product of prime numbers. Such a product representation is called prime factorization.

For Example:

300 = 2 ^ 2 * 3 ^ 1 * 5 ^ 2
580 = 2 ^ 2 * 5 ^ 1 * 29 ^ 1

Prime Factorization Program Implementation in Python
Write a program to display the prime factorization of a given number in Python.


from math import sqrt a=int(input()) t,b,i=[],a,3 while not(a%2): t.append(2) a//=2 while i<=a: if a%i == 0: a//=i t.append(i) else: i+=2 if 1 in t: t.remove(1) print('{} = '.format(b),end='') print(*['{}{}'.format(p,'^'+str(t.count(p)) if t.count(p)>1 else '') for p in sorted(set(t))],sep=' x ')


186 = 2 x 3 x 31

Facing Programming Errors. Get Answer within 48 hours:

Giving is the Master Key to Success, in all applications of human life.


For Sponsored Advertisement OR Freelance Programming Article Submission, Contact us at
Recommended Deals Ends in

Quiz Challenge:
Online Games
Play 2048 Game Online and Relax.
Play 2048 Game Online

Search Tags

    Find Prime factorization using Python

    Efficient Program to Print all prime factors of a given number

    Compute Prime Factors of an integer in Python

    Python Program to Compute Prime Factors of an Integer