human
Give me a code to segregate Prime and Non and the other steps required given the following:
Segregate Prime and Non | Function to generate prime numbers using Sieve of Eratosthenes.
If prime [ p ] is unchanged , then it is a prime.
Update all multiples of p.
Function to segregate the primes and non - primes.
Generate all primes till 10 ^ 7.
Initialize left and right.
Traverse the array.
Increment left while array element at left is prime.
Decrement right while array element at right is non - prime.
If left < right , then swap arr [ left ] and arr [ right ].
Swap arr [ left ] and arr [ right ].
Print segregated array.
Driver code.
Function Call"
Solution in Python:
assistant
#Here is code to segregate Prime and Non and the other steps required.
 def SieveOfEratosthenes ( prime , n ) :
	p = 2
	while ( p * p <= n ) :
		if ( prime [ p ] == True ) :
			i = p * p
			while ( i <= n ) :
				prime [ i ] = False
				i += p
		p += 1
def segregatePrimeNonPrime ( prime , arr , N ) :
	SieveOfEratosthenes ( prime , 10000000 )
	left , right = 0 , N - 1
	while ( left < right ) :
		while ( prime [ arr [ left ] ] ) :
			left += 1
		while ( not prime [ arr [ right ] ] ) :
			right -= 1
		if ( left < right ) :
			arr [ left ] , arr [ right ] = arr [ right ] , arr [ left ]
			left += 1
			right -= 1
	for num in arr :
		print ( num , end = " ▁ " )
arr = [ 2 , 3 , 4 , 6 , 7 , 8 , 9 , 10 ]
N = len ( arr )
prime = [ True ] * 10000001
segregatePrimeNonPrime ( prime , arr , N )