Print numbers such that no two consecutive numbers are co | Python3 program for the above approach ; Function for Sieve of Eratosthenes ; Function to print the required sequence ; Store only the required primes ; Base condition ; First integer in the list ; Second integer in the list ; Third integer in the list ; Generate ( N - 1 ) th term ; Generate Nth term ; Modify first term ; Print the sequence ; Driver code
MAX = 620000 NEW_LINE prime = [ 0 ] * MAX NEW_LINE def Sieve ( ) : NEW_LINE INDENT for i in range ( 2 , MAX ) : NEW_LINE INDENT if ( prime [ i ] == 0 ) : NEW_LINE INDENT for j in range ( 2 * i , MAX , i ) : NEW_LINE INDENT prime [ j ] = 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT def printSequence ( n ) : NEW_LINE INDENT Sieve ( ) NEW_LINE v = [ ] NEW_LINE u = [ ] NEW_LINE for i in range ( 13 , MAX ) : NEW_LINE INDENT if ( prime [ i ] == 0 ) : NEW_LINE INDENT v . append ( i ) NEW_LINE DEDENT DEDENT if ( n == 3 ) : NEW_LINE INDENT print ( 6 , 10 , 15 ) NEW_LINE return NEW_LINE DEDENT k = 0 NEW_LINE for k in range ( n - 2 ) : NEW_LINE INDENT if ( k % 3 == 0 ) : NEW_LINE INDENT u . append ( v [ k ] * 6 ) NEW_LINE DEDENT elif ( k % 3 == 1 ) : NEW_LINE INDENT u . append ( v [ k ] * 15 ) NEW_LINE DEDENT else : NEW_LINE INDENT u . append ( v [ k ] * 10 ) NEW_LINE DEDENT DEDENT u . append ( v [ k ] * 7 ) NEW_LINE u . append ( 7 * 11 ) NEW_LINE u [ 0 ] = u [ 0 ] * 11 NEW_LINE print ( * u ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 4 NEW_LINE printSequence ( n ) NEW_LINE DEDENT