Table of Contents
Introduction
The task is to print the product of unique prime factors of the given number.
Program
def find(ip_num): # Initializing product with 1 prod = 1 for num in range(2, ip_num+1): if (ip_num % num == 0): prime_true = 1 for num2 in range(2, int(num/2 + 1)): if (num % num2 == 0): prime_true = 0 break # Getting product if number is prime if (prime_true): prod = prod * num print("Product of unique prime factors of number {0} are {1} ".format(ip_num,prod) ) ip_num = int(input("Enter the number: ")) find(ip_num)
Output
Explanation
Approach:
- Traverse through num in range(2, N).
- Check whether num divides the given number N.
- If yes, then check whether num is a prime number. If num is prime then store the product in a variable.
- Repeat the above steps and print the output product.
0 Comments