Remove two consecutive integers from 1 to N to make sum equal to S | C ++ program remove two consecutive integers from 1 to N to make sum equal to S ; Function to find the numbers to be removed ; typecast appropriately so that answer is float ; return the obtained result ; Convert i to integer ; If i is an integer is 0 then answer is Yes ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; float findNumber ( int N , int S ) { float i = ( ( ( float ) ( N ) * ( float ) ( N + 1 ) ) / 4 ) - ( ( float ) ( S + 1 ) / 2 ) ; return i ; } void check ( int N , int S ) { float i = findNumber ( N , S ) ; int integerI = ( int ) i ; if ( i - integerI == 0 ) cout << " Yes : ▁ " << integerI << " , ▁ " << integerI + 1 << endl ; else cout << " No " << endl ; } int main ( ) { int N = 4 , S = 3 ; check ( N , S ) ; N = 5 , S = 3 ; check ( N , S ) ; return 0 ; }