Given three integers A, B, N. Your task is to print the number of numbers between A and B including them, which have N-divisors. A number is called N-divisor if it has total N divisors including 1 and itself.
 
Example 1:
Input:
A = 1
B = 7
N = 2
Output:
4
Explanation:
2,3,5,7 have 2-divisors
Example 2:
Input:
A = 1
B = 25
N = 3
Output:
3
Explanation:
4,9,25 are the numbers
having 3-divisors
Your Task:
You don't need to read input or print anything. Your task is to complete the function count() which takes integer A, B and N as input parameters and returns an integer, the number of N-divisor number in between A and B inclusive.
 
Expected Time Complexity: O((B-A) sqrt (B))
Expected Space Complexity: O(1)
 
Constraints:
1<=A<=B<=10^{4}
1 <= N <= 16

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
    def count(self,A,B,N): 
        # code here

Solutions:
class Solution:

	def count(self, A, B, N):
		ans = 0
		for x in range(A, B + 1):
			count = 0
			i = 1
			while i * i <= x:
				if x % i == 0:
					count += 1
					if x // i != i:
						count += 1
					if count > N:
						break
				i += 1
			if count == N:
				ans += 1
		return ans


import math

class Solution:

	def count(self, A, B, N):
		p = 0
		for i in range(A, B + 1):
			c = 0
			for j in range(1, int(math.sqrt(i)) + 1):
				if i % j == 0:
					l = int(i / j)
					if l != j:
						c += 2
					else:
						c += 1
			if c == N:
				p += 1
		return p
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(A, B, N) = input().split()
		A = int(A)
		B = int(B)
		N = int(N)
		ob = Solution()
		print(ob.count(A, B, N))


from math import *

class Solution:

	def count(self, A, B, N):
		count = 0
		sol = Solution()
		for i in range(A, B + 1):
			if N == sol.counter(i):
				count += 1
		return count

	def counter(self, N):
		count = 0
		for i in range(1, int(sqrt(N)) + 1):
			if N % i == 0:
				if N % (N // i) == 0 and N // i != i:
					count += 1
				count += 1
		return count