- Related Questions & Answers
- C Program for efficiently print all prime factors of a given number?
- Python Program for Product of unique prime factors of a number
- Program to find all prime factors of a given number in sorted order in Python
- Product of unique prime factors of a number in Python Program
- Find all prime factors of a number - JavaScript
- Java program to print a prime number
- Java Program to find Product of unique prime factors of a number
- Python Program to print all permutations of a given string
- Python Program for Find sum of even factors of a number
- Python Program for Find sum of odd factors of a number
- Python Program for Number of elements with odd factors in the given range
- Python Program for Find minimum sum of factors of number
- C/C++ Program to find Product of unique prime factors of a number?
- Python Program for Find largest prime factor of a number
- Python program to print all the numbers divisible by 3 and 5 for a given number

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this article, we will learn about the solution to the problem statement given below.

**Problem statement **− We are given a number, we need to find all the prime factors of a given number.

The efficient solution to the problem is discussed below −

# Python program to print prime factors import math # prime def primeFactors(n): # no of even divisibility while n % 2 == 0: print (2), n = n / 2 # n reduces to become odd for i in range(3,int(math.sqrt(n))+1,2): # while i divides n while n % i== 0: print (i) n = n / i # if n is a prime if n > 2: print (n) n = 200 primeFactors(n)

2 2 2 5 5

All the variables and functions are declared in the global scope as shown in the figure above.

In this article, we have learned how we can print all prime factors of a given number efficiently.

Advertisements