Partition first N natural number into two sets such that their sum is not coprime | C ++ implementation of the approach ; Function to find the required sets ; Impossible case ; Sum of first n - 1 natural numbers ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void find_set ( int n ) { if ( n <= 2 ) { cout << " - 1" ; return ; } int sum1 = ( n * ( n - 1 ) ) / 2 ; int sum2 = n ; cout << sum1 << " ▁ " << sum2 ; } int main ( ) { int n = 8 ; find_set ( n ) ; return 0 ; }