human
Sieve of Sundaram to print all primes smaller than n | Prints all prime numbers smaller.
In general Sieve of Sundaram , produces primes smaller than ( 2 * x + 2 ) for a number given number x . Since we want primes smaller than n , we reduce n to half.
This array is used to separate numbers of the form i + j + 2 ij from others where 1 <= i <= j Initialize all elements as not marked.
Main logic of Sundaram . Mark all numbers of the form i + j + 2 ij as true where 1 <= i <= j.
Since 2 is a prime number.
Print other primes . Remaining primes are of the form 2 * i + 1 such that marked [ i ] is false ..
Driver Code"
Solution in Python:
 ... Write me a code to sieve of Sundaram to print all primes smaller than n and the other steps required?
assistant
#Here is code to sieve of Sundaram to print all primes smaller than n and the other steps required.
 def SieveOfSundaram ( n ) :
	nNew = int ( ( n - 1 ) / 2 ) ;
	marked = [ 0 ] * ( nNew + 1 ) ;
	for i in range ( 1 , nNew + 1 ) :
		j = i ;
		while ( ( i + j + 2 * i * j ) <= nNew ) :
			marked [ i + j + 2 * i * j ] = 1 ;
			j += 1 ;
	if ( n > 2 ) :
		print ( 2 , end = " ▁ " ) ;
	for i in range ( 1 , nNew + 1 ) :
		if ( marked [ i ] == 0 ) :
			print ( ( 2 * i + 1 ) , end = " ▁ " ) ;
n = 20 ;
SieveOfSundaram ( n ) ;