![]() |
VOOZH | about |
Given a number n, the task is to find the product of all its unique prime factors. A prime factor is a prime number that divides n exactly without leaving a remainder. For Examples:
Input: 10
Output: Product is 10
Explanation: prime factors of 10 are 2 and 5 and their product is 10.
Let's explore different methods to find the product of unique prime factors of a number in python.
In this method, we use the built-in primefactors() function that directly returns a list of unique prime factors of a number. We then compute their product using math.prod().
Output
22
This approach is similar to the SymPy method but uses numpy.prod() for computing the product efficiently when handling large factor lists.
Output
22
In this method, we divide the number by 2 until it’s no longer divisible, then check divisibility by odd numbers up to its square root. Each prime divisor is multiplied only once to form the final product.
22
Explanation:
In this method, we check each number from 2 to n. If it divides n, we check whether it’s prime by testing divisibility up to its half. Each prime divisor contributes once to the final product.
22
Explanation: