Check if all Prime factors of number N are unique or not | Function that returns the all the distinct prime factors in a vector ; If n is divisible by 2 ; Divide n till all factors of 2 ; Check for the prime numbers other than 2 ; Store i in Prime [ ] i is a factor of n ; Divide n till all factors of i ; If n is greater than 2 , then n is prime number after n divided by all factors ; Returns the vector Prime ; Function that check whether N is the product of distinct prime factors or not ; Returns the vector to store all the distinct prime factors ; To find the product of all distinct prime factors ; Find the product ; If product is equals to N , print YES , else print NO ; Driver Code
def primeFactors ( n ) : NEW_LINE INDENT Prime = [ ] ; NEW_LINE if ( n % 2 == 0 ) : NEW_LINE INDENT Prime . append ( 2 ) ; NEW_LINE DEDENT while ( n % 2 == 0 ) : NEW_LINE INDENT n = n // 2 ; NEW_LINE DEDENT for i in range ( 3 , int ( n ** ( 1 / 2 ) ) , 2 ) : NEW_LINE INDENT if ( n % i == 0 ) : NEW_LINE INDENT Prime . append ( i ) ; NEW_LINE DEDENT while ( n % i == 0 ) : NEW_LINE INDENT n = n // i ; NEW_LINE DEDENT DEDENT if ( n > 2 ) : NEW_LINE INDENT Prime . append ( n ) ; NEW_LINE DEDENT return Prime ; NEW_LINE DEDENT def checkDistinctPrime ( n ) : NEW_LINE INDENT Prime = primeFactors ( n ) ; NEW_LINE product = 1 ; NEW_LINE for i in Prime : NEW_LINE INDENT product *= i ; NEW_LINE DEDENT if ( product == n ) : NEW_LINE INDENT print ( " YES " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 30 ; NEW_LINE checkDistinctPrime ( N ) ; NEW_LINE DEDENT