Python Program to Print Prime Factor of Given Number
In this tutorial, we will discuss how we can get the prime factor of the given number using the Python program. All we familiar with the prime numbers, if not then prime numbers are the number that can be divided by one or itself. For example - 1, 2, 3, 5, 7, 11, 13, ……
Finding all prime factorization of a number
If the user enters the number as 12, then the output must be '2, 2, 3, and if the input is 315; the output should be "3 3 5 7". The program must return the prime all prime factor of given number. The prime factors of 330 are 2, 3, 5, and 11. Therefore 11 is the most significant prime factor of 330.
For Example: 330 = 2 × 3 × 5 × 11.
Before writing the Python program, let's understand the following conjectures.
Proof -There are two greater sqrt(n) numbers, then their product should also divide n but which will exceed n, which contradicts our assumption. So there can NOT be more than one prime factor of n greater than sqrt(n).
Let's see the following step to perform such an operation.
Proof - Suppose there are two greater sqrt(n) number then their product should also divide n but which will exceed n, which contradicts our assumption. So there can NOT be more than 1 prime factor of n greater than sqrt(n).
Let's see the following step to perform such operation.
Example - Python program to print prime factors
2 2 2 5 5
In the above code, we have imported the math module. The prime_factor() function is responsible for printing the composite number. First, we get the even numbers; after this, all remaining prime factors must be odd. In for loop, the num must be odd, so we incremented i by two. A for loop will run the square root of n times.
Let's understand the following property of composite numbers.
Every composite number has at least one prime factor less than or equal to the square root.
The program will work as follows.
Let's understand another example where we find the largest prime factor of a given number.
Example - 2 Python program to find the largest prime factor of a given number.
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week