
Let N = 42
N = 2 * 3 * 7
Here, 2, 3 and 7 are 3 distinct prime numbers. Thus, 42 is a sphenic number.
Let N = 60
N = 2 * 2 * 3 * 5
Here, 2, 3, and 5 are distinct prime numbers, but 2 is repeated twice. A sphenic number is a product of exactly 3 distinct primes. Thus, 60 is not a sphenic number.
Let N = 15
N = 3 * 5
Here, 3 & 5 are only 2 distinct prime numbers but, we need 3 distinct prime numbers. Thus, 15 is not a sphenic number.
The first line of input contains an integer 'T' denoting the number of queries or test cases.
The first and only line of each input contains an integer 'N'.
For each test case, print ‘Yes’ if the given number is a sphenic number; otherwise, print ‘No’ in a separate line.
The output of each test case should be printed in a separate line.
You do not need to print anything, and it has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= N <= 10^8
where 'T' is the number of test cases and 'N' is the given integer.
Time Limit: 1 sec.
Let’s take an example where N = 30
→ First iteration:
As the smallest prime factor of 30 is 2 i.e. sieve[30] = 2, so, we divide 30 by 2 and increase the count to 1 and update prev to 2.
We update 30 with 30 / 2 i.e. 15.
→ Second iteration:
Now, the smallest prime factor of 15 is 3 i.e. sieve[15] = 3, so, we divide 15 by 3 and increase the count to 2 and update prev to 3.
We update 15 with 15 / 3 i.e. 5.
→ Third iteration:
The smallest prime factor of 5 is 5 i.e. sieve[5] = 5, so, we divide 5 by 5 and increase the count to 3 and update prev to 5.
We update 5 with 5 / 5 i.e. 1.
As, N becomes equal to 1, so, while loop will be ended and as the count is equal to 3, it is a sphenic number.
We will do the prime factorization of N by dividing it by its factors smaller than its square root. And at last, we will be left with its largest prime factor of N. Thus, we will check for the count of prime factors to be equal to 2 and not 3.
Let’s take an example where N = 42
→ First iteration i = 2:
As 42 is divisible by 2, so we divide 42 by 2. Thus, N = 21
Increase count to 1
Now 21 is not divisible by 2, this means, till now it can be considered as Sphenic number.
As 21 is divisible by 3, so we divide 21 by 3. Thus N = 7
Increase count to 2
Now 7 is not divisible by 3, this means, till now it can be considered as Sphenic number.
→ We exit the loop on the third iteration as i = 4 and 4*4 is greater than 7.
Now as the count is equal to 2, so it is a sphenic number.
Pair Product Div by K
Pair Product Div by K
Merge Two Sorted Arrays Without Extra Space
Merge Two Sorted Arrays Without Extra Space
Co-Prime
First Digit One
Special Digit Numbers