
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Program for Efficient program to print all prime factors of a given number
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 −
Example
# 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)
Output
2 2 2 5 5
All the variables and functions are declared in the global scope as shown in the figure above.
Conclusion
In this article, we have learned how we can print all prime factors of a given number efficiently.
- Related Articles
- C Program for efficiently print all prime factors of a given number?
- Program to find all prime factors of a given number in sorted order in Python
- Python Program for Product of unique prime factors of a number
- Product of unique prime factors of a number in Python Program
- Java program to print a prime number
- Python Program to print all permutations of a given string
- Python program to print all the numbers divisible by 3 and 5 for a given number
- Python program to print all Prime numbers in an Interval
- Python Program to Print all Numbers in a Range Divisible by a Given Number
- Java Program to find Product of unique prime factors of a number
- Find all prime factors of a number - JavaScript
- Python Program for Number of elements with odd factors in the given range
- Python program to print all distinct elements of a given integer array.
- Python Program for Find sum of even factors of a number
- Python Program for Find sum of odd factors of a number

Advertisements