human
Find Nth smallest number having exactly 4 divisors | Function to find the nth number which has exactly 4 divisors.
The divs [ ] array to store number of divisors of every element.
The vis [ ] array to check if given number is considered or not.
The cnt stores number of elements having exactly 4 divisors.
Iterate while cnt less than n.
If i is a prime.
Iterate in the range [ 2 * i , 1000000 ] with increment of i.
If the number j is already considered.
Dividing currNum by i until currNum % i is equal to 0.
Case a single prime in its factorization.
Case of two distinct primes which divides j exactly once each.
Given Input.
Function Call"
How can the above be solved in Python?
 What is a code to find Nth smallest number having exactly 4 divisors and the other steps required?
assistant
#Here is code to find Nth smallest number having exactly 4 divisors and the other steps required.
 def nthNumber ( n ) :
	divs = [ 0 for i in range ( 1000000 ) ] ;
	vis = [ 0 for i in range ( 1000000 ) ] ;
	cnt = 0 ;
	for i in range ( 2 , n ) :
		if ( divs [ i ] == 0 ) :
			for j in range ( 2 * i , 1000000 ) :
				if ( vis [ j ] ) :
					continue ;
				vis [ j ] = 1 ;
				currNum = j ;
				count = 0 ;
				while ( currNum % i == 0 ) :
					divs [ j ] += 1 ;
					currNum = currNum // i ;
					count += 1 ;
				if ( currNum == 1 and count == 3 and divs [ j ] == 3 ) :
					cnt += 1
				elif ( currNum != 1 and divs [ currNum ] == 0 and count == 1 and divs [ j ] == 1 ) :
					cnt += 1
				if ( cnt == n ) :
					return j ;
	return - 1 ;
N = 24 ;
print ( nthNumber ( N ) ) ;