Possible two sets from first N natural numbers difference of sums as D | Java program for implementing above approach ; Function returns true if it is possible to split into two sets otherwise returns false ; Driver code
class GFG { static boolean check ( int N , int D ) { int temp = ( N * ( N + 1 ) ) / 2 + D ; return ( temp % 2 == 0 ) ; } static public void main ( String args [ ] ) { int N = 5 ; int M = 7 ; if ( check ( N , M ) ) System . out . println ( " yes " ) ; else System . out . println ( " no " ) ; } }