Given a positive integer value N. The task is to find how many numbers less than or equal to N have numbers of divisors exactly equal to 3.
Example 1:
Input:
N = 6
Output: 1
Explanation: The only number with
3 divisor is 4.
Example 2:
Input:
N = 10
Output: 2
Explanation: 4 and 9 have 3 divisors.
Your Task:
You don't need to read input or print anything. Your task is to complete the function exactly3Divisors() that takes N as parameter and returns count of numbers less than or equal to N with exactly 3 divisors.
Expected Time Complexity : O(N1/2 * N1/4)
Expected Auxilliary Space : O(1)
Constraints :
1 <= N <= 109
__________________________________________________________-
def isprime(n):
if n==2:
return True
for i in range(2, int(n**0.5)+1):
if n%i==0:
return False
return True
##Complete this function
def exactly3Divisors(N):
##Your code here
n = int(N**0.5)
c=0
for i in range(2, n+1):
if isprime(i):
c+=1
return c
Comments
Post a Comment