human
Write me a code to find n and the other steps required given the following:
Find n | Python3 program to find n - th Fortunate number.
Corner cases.
This is checked so that we can skip middle five numbers in below loop.
Function to Find primorial of order n ( product of first n prime numbers ) ..
Function to find next prime number greater than n.
Note that difference ( or m ) should be greater than 1..
loop continuously until isPrime returns true for a number above n.
Ignoring the prime number that is 1 greater than n.
Returns n - th Fortunate number.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to find n and the other steps required.
 def isPrime ( n ) :
	if ( n <= 1 ) : return False
	if ( n <= 3 ) : return True
	if ( n % 2 == 0 or n % 3 == 0 ) :
		return False
	i = 5
	while ( i * i <= n ) :
		if ( n % i == 0 or n % ( i + 2 ) == 0 ) :
			return False
		i += 6
	return True
def primorial ( n ) :
	p = 2 ; n -= 1 ; i = 3
	while ( n != 0 ) :
		if ( isPrime ( i ) ) :
			p = p * i
			n -= 1
		i += 1
	return p
def findNextPrime ( n ) :
	nextPrime = n + 2
	while ( True ) :
		if ( isPrime ( nextPrime ) ) :
			break
		nextPrime += 1
	return nextPrime
def fortunateNumber ( n ) :
	p = primorial ( n )
	return findNextPrime ( p ) - p
n = 5
print ( fortunateNumber ( n ) )