Three distinct factors
Basic Accuracy: 20.35% Submissions: 59 Points: 1

Given a positive integer N. The task is to check whether a number has exactly three distinct factors or not.

 

Example 1:

Input:
N = 10
Output:
0
Explanation:
10 has 4 factors- 1,2,5 and 10.
So, the Ouput is 0.

Example 2:

Input:
N = 9
Output:
1
Explanation:
9 has 3 factors- 1,3 and 9.
So, the Ouput is 1.

 

Your Task:
You don't need to read input or print anything. Your task is to complete the function hasThreePrimeFac() which takes an Integer N as input and returns 1 if it has exactly 3 factors else returns 1.

 

Expected Time Complexity: O(sqrt(N))
Expected Auxiliary Space: O(1)

 

Constraints:
1 <= N <= 1012

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Output Window