Distinct Prime Factors of Product of Array

Given an array of positive integers nums, return the number of distinct prime factors in the product of the elements of nums.

Note that:

  • A number greater than 1 is called prime if it is divisible by only 1 and itself.
  • An integer val1 is a factor of another integer val2 if val2 / val1 is an integer.
Example 1
Inputnums = [2,4,3,7,10,6]
Output4
The product is 10080 = 2^5 * 3^2 * 5 * 7, so there are 4 distinct prime factors.
Example 2
Inputnums = [2,4,8,16]
Output1
The product is 1024 = 2^10, so there is 1 distinct prime factor.

Constraints

  • 1 <= nums.length <= 10^4
  • 2 <= nums[i] <= 1000

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate