Split N natural numbers into two sets having GCD of their sums greater than 1 | C ++ program to split N natural numbers into two sets having GCD of their sums greater than 1 ; Function to create and print the two sets ; No such split possible for N <= 2 ; Print the first set consisting of even elements ; Print the second set consisting of odd ones ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void createSets ( int N ) { if ( N <= 2 ) { cout << " - 1" << endl ; return ; } for ( int i = 2 ; i <= N ; i += 2 ) cout << i << " ▁ " ; cout << " STRNEWLINE " ; for ( int i = 1 ; i <= N ; i += 2 ) { cout << i << " ▁ " ; } } int main ( ) { int N = 6 ; createSets ( N ) ; return 0 ; }