Print all distinct Coprime sets possible from 1 to N | Function to prall co - prime sets ; Check if n is less than 4 then simply prall values till n ; For all the values of n > 3 ; Check if n is even then every set will contain 2 adjacent elements up - to n ; If n is odd then every set will contain 2 adjacent element except the last set which will have last three elements ; Last element for odd case ; Driver code
def coPrimeSet ( n ) : NEW_LINE INDENT firstadj = 0 ; NEW_LINE secadj = 0 ; NEW_LINE if ( n < 4 ) : NEW_LINE INDENT print ( " ( ▁ " ) ; NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT print ( i + " , ▁ " ) ; NEW_LINE DEDENT print ( " ) " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT if ( n % 2 == 0 ) : NEW_LINE INDENT for i in range ( 0 , n / 2 ) : NEW_LINE INDENT firstadj = 2 * i + 1 ; NEW_LINE secadj = 2 * i + 2 ; NEW_LINE print ( " ( " , firstadj , " , ▁ " , secadj , " ) " ) ; NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT for i in range ( 0 , int ( n / 2 ) - 1 ) : NEW_LINE INDENT firstadj = 2 * i + 1 ; NEW_LINE secadj = 2 * i + 2 ; NEW_LINE print ( " ( " , firstadj , " , ▁ " , secadj , " ) " ) ; NEW_LINE DEDENT print ( " ( " , ( n - 2 ) , " , ▁ " , ( n - 1 ) , " , ▁ " , n , " ) " ) ; NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 5 ; NEW_LINE coPrimeSet ( n ) ; NEW_LINE DEDENT