Python Program for Product of unique prime factors of a number Last Updated : 14 Mar, 2023 Comments Improve Suggest changes Like Article Like Report Given a number n, we need to find the product of all of its unique prime factors. Prime factors: It is basically a factor of the number that is a prime number itself. Examples: Input: num = 10 Output: Product is 10 Explanation: Here, the input number is 10 having only 2 prime factors and they are 5 and 2. And hence their product is 10. Input : num = 25 Output: Product is 5 Explanation: Here, for the input to be 25 we have only one unique prime factor i.e 5. And hence the required product is 5. Method 1 (Simple) Using a loop from i = 2 to n and check if i is a factor of n then check if i is prime number itself if yes then store product in product variable and continue this process till i = n. Python3 # Python program to find sum of given # series. def productPrimeFactors(n): product = 1 for i in range(2, n+1): if (n % i == 0): isPrime = 1 for j in range(2, int(i/2 + 1)): if (i % j == 0): isPrime = 0 break # condition if \'i\' is Prime number # as well as factor of num if (isPrime): product = product * i return product # main() n = 44 print(productPrimeFactors(n)) # Contributed by _omg Output: 22 Time complexity: O(n^2/2)Auxiliary space: O(1) Method 2 (Efficient) : The idea is based on Efficient program to print all prime factors of a given number Python3 # Python program to find product of # unique prime factors of a number import math def productPrimeFactors(n): product = 1 # Handle prime factor 2 explicitly so that # can optimally handle other prime factors. if (n % 2 == 0): product *= 2 while (n%2 == 0): n = n/2 # n must be odd at this point. So we can # skip one element (Note i = i +2) for i in range (3, int(math.sqrt(n)), 2): # While i divides n, print i and # divide n if (n % i == 0): product = product * i while (n%i == 0): n = n/i # This condition is to handle the case when n # is a prime number greater than 2 if (n > 2): product = product * n return product # main() n = 44 print (int(productPrimeFactors(n))) # Contributed by _omg Output: 22 Time complexity: O(sqrt(n)), where n is the input number.Auxiliary space: O(1), as the program only uses a constant amount of memory to store the product and the loop variables. Please refer complete article on Product of unique prime factors of a number for more details! Comment More infoAdvertise with us Next Article Python Program for Product of unique prime factors of a number K kartik Follow Improve Article Tags : DSA Python Programs Similar Reads Python program to find product of given number of consecutive elements Given a List, the task is to write a python program that can construct a list with products of consecutive elements for a given number of elements. Input : test_list = [5, 6, 2, 1, 7, 5, 3], K = 3 Output : [60, 12, 14, 35, 105] Explanation : 5 * 6 * 2 = 60, 6 * 2 * 1 = 12.. And so on. Input : test_l 3 min read Factorial of a Number - Python The factorial of a number is the product of all positive integers less than or equal to that number. For example, the factorial of 5 (denoted as 5!) is 5 Ã 4 Ã 3 Ã 2 Ã 1 = 120. In Python, we can calculate the factorial of a number using various methods, such as loops, recursion, built-in functions, 4 min read Python | Product of Prefix in list Nowadays, especially in competitive programming, the utility of computing prefix product is quite popular and features in many problems. Hence, having a one-liner solution to it would possess a great help. Letâs discuss certain ways in which this problem can be solved. Method 1: Using list comprehen 4 min read Check Prime Number in Python Given a positive integer N, the task is to write a Python program to check if the number is Prime or not in Python. For example, given a number 29, it has no divisors other than 1 and 29 itself. Hence, it is a prime number.Note: Negative numbers (e.g. -13) are not considered prime number.Using sympy 7 min read Python | Sliced Product in List Accessing elements in a list has many types and variations. These are an essential part of Python programming and one must know to perform the same. This article discusses ways to fetch the initial K elements and do its multiplication. Letâs discuss a certain solution to perform this task. Method #1 5 min read Like