Numbers with Exactly Three Divisors
Problem statement
Call a positive integer almost prime if it has exactly three positive divisors. For example, 9 is almost prime because its divisors are 1, 3, and 9.
You are given an integer array nums. Return a boolean array answer of the same length, where answer[i] is true if nums[i] is almost prime and false otherwise.
Function
almostPrimes(nums: int[]) → boolean[]Examples
Example 1
nums = [4,6,9,25,1]return = [true,false,true,true,false]4 has divisors 1, 2, 4, 9 has 1, 3, 9, and 25 has 1, 5, 25, so they are almost prime. 6 has four divisors and 1 has only one.
Example 2
nums = [8,16,49]return = [false,false,true]8 has divisors 1, 2, 4, 8 and 16 has 1, 2, 4, 8, 16, so neither has exactly three. 49 has 1, 7, 49.
Example 3
nums = [961,1000000000]return = [true,false]961 = 31 * 31, and 31 is prime, so the divisors are 1, 31, 961. 1000000000 has many divisors, such as 2, 5, and 10.
Constraints
1 <= nums.length <= 10^51 <= nums[i] <= 10^9