Check whether a number can be represented as sum of K distinct positive integers | Function that returns true if n can be represented as the sum of exactly k distinct positive integers ; If n can be represented as 1 + 2 + 3 + ... + ( k - 1 ) + ( k + x ) ; Driver code
< ? php function solve ( $ n , $ k ) { if ( $ n >= ( $ k * ( $ k + 1 ) ) / 2 ) { return true ; } return false ; } $ n = 12 ; $ k = 4 ; if ( solve ( $ n , $ k ) ) echo " Yes " ; else echo " No " ; ? >