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 ; For n <= 2 such sets can never be formed ; Check if N is even or odd and store the element which divides the sum of N natural numbers accordingly ; First set ; Print elements of second set ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define ll  long long NEW_LINE void createSets ( ll n ) { if ( n <= 2 ) { cout << " - 1" ; return ; } else { ll x = ( n % 2 == 0 ) ? ( n / 2 ) : ( ( n + 1 ) / 2 ) ; cout << x << endl ; for ( ll i = 1 ; i <= n ; i ++ ) { if ( i == x ) continue ; cout << i << " ▁ " ; } } return ; } int main ( ) { ll N = 7 ; createSets ( N ) ; return 0 ; }