Cake Distribution Problem | Function to return the remaining count of cakes ; Sum for 1 cycle ; no . of full cycle and remainder ; Driver code
def cntCakes ( n , m ) : NEW_LINE INDENT sum = ( n * ( n + 1 ) ) // 2 NEW_LINE quo , rem = m // sum , m % sum NEW_LINE ans = m - quo * sum NEW_LINE x = int ( ( - 1 + ( 8 * rem + 1 ) ** 0.5 ) / 2 ) NEW_LINE ans = ans - x * ( x + 1 ) // 2 NEW_LINE return ans NEW_LINE DEDENT def main ( ) : NEW_LINE INDENT n = 4 NEW_LINE m = 11 NEW_LINE ans = cntCakes ( n , m ) NEW_LINE print ( ans ) NEW_LINE DEDENT main ( ) NEW_LINE