Split N natural numbers into two sets having GCD of their sums greater than 1 | Java 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
class GFG { static void createSets ( long n ) { if ( n <= 2 ) { System . out . print ( " - 1" ) ; return ; } else { long x = ( n % 2 == 0 ) ? ( n / 2 ) : ( ( n + 1 ) / 2 ) ; System . out . print ( x + "NEW_LINE"); for ( int i = 1 ; i <= n ; i ++ ) { if ( i == x ) continue ; System . out . print ( i + " ▁ " ) ; } } return ; } public static void main ( String [ ] args ) { long N = 7 ; createSets ( N ) ; } }