Count ways to remove objects such that exactly M equidistant objects remain | Function to count the number of ways of removing objects such that after removal , exactly M equidistant objects remain ; Store the resultant number of arrangements ; Base Case : When only 1 object is left ; Print the result and return ; Iterate until len <= n and increment the distance in each iteration ; Total length if adjacent objects are d distance apart ; If length > n ; Update the number of ways ; Print the result ; Driver Code
def waysToRemove ( n , m ) : NEW_LINE INDENT ans = 0 NEW_LINE if ( m == 1 ) : NEW_LINE INDENT print ( n ) NEW_LINE return NEW_LINE DEDENT d = 0 NEW_LINE while d >= 0 : NEW_LINE INDENT length = m + ( m - 1 ) * d NEW_LINE if ( length > n ) : NEW_LINE INDENT break NEW_LINE DEDENT ans += ( n - length ) + 1 NEW_LINE d += 1 NEW_LINE DEDENT print ( ans ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 5 NEW_LINE M = 3 NEW_LINE waysToRemove ( N , M ) NEW_LINE DEDENT