Possible two sets from first N natural numbers difference of sums as D | C ++ program for implementing above approach ; Function returns true if it is possible to split into two sets otherwise returns false ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool check ( int N , int D ) { int temp = ( N * ( N + 1 ) ) / 2 + D ; return ( temp % 2 == 0 ) ; } int main ( ) { int N = 5 ; int M = 7 ; if ( check ( N , M ) ) cout << " yes " ; else cout << " no " ; return 0 ; }