Partition first N natural number into two sets such that their sum is not coprime | Java implementation of the approach ; Function to find the required sets ; Impossible case ; Sum of first n - 1 natural numbers ; Driver code
import java . io . * ; class GFG { static void find_set ( int n ) { if ( n <= 2 ) { System . out . println ( " - 1" ) ; return ; } int sum1 = ( n * ( n - 1 ) ) / 2 ; int sum2 = n ; System . out . println ( sum1 + " ▁ " + sum2 ) ; } public static void main ( String [ ] args ) { int n = 8 ; find_set ( n ) ; } }