Program to find product of unique prime factors of a given number using Python

by | Aug 14, 2021 | Python Programs

Home » Python » Python Programs » Program to find product of unique prime factors of a given number using Python

Introduction

The task is to print the product of unique prime factors of the given number.

Program to find product of unique prime factors of a given number using Python

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

Program to find product of unique prime factors of a given number using Python 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.

Author

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Author