low
and high
bounds to strings for easier digit manipulation.dp
with parameters: current index, tight constraint (whether we are at the edge of the current bounds), count of even digits, count of odd digits, current remainder modulo k
, and a flag indicating whether we have started forming the number (to handle leading zeros).k
(remainder is 0).dp
function.dp
function for the high
bound and subtract the result of calling dp
for the low - 1
bound to get the final count of beautiful integers.