text: Check if N can be divided into K consecutive elements with a sum equal to N | C # program for the above approach ; Function to find the K consecutive elements with a sum equal to N ; Iterate over [ 2 , INF ] ; Store the sum ; If the sum exceeds N then break the loop ; Common difference should be divisible by number of terms ; Print value of i & return ; Print " - 1" if not possible to break N ; Driver Code ; Given N ; Function call
code: using System ; class GFG { public static void canBreakN ( long n ) { for ( long i = 2 ; ; i ++ ) { long m = i * ( i + 1 ) / 2 ; if ( m > n ) break ; long k = n - m ; if ( k % i != 0 ) continue ; Console . Write ( i ) ; return ; } Console . Write ( " - 1" ) ; } public static void Main ( string [ ] args ) { long N = 12 ; canBreakN ( N ) ; } }