A fleet maintenance app watches the rolling digital odometer of a delivery van. The odometer displays a positive integer reading with no leading zero. For a chosen window width k, the app scans every contiguous block of k digits within the display, sliding one digit at a time from left to right so that consecutive blocks overlap, and reads each block as its own integer (a block such as "05" is read as the integer 5, so leading zeros inside a block are allowed and simply shrink its value). A block is called resonant if its value is strictly positive and it evenly divides the full odometer reading. Determine how many of the blocks are resonant.
Line 1: an integer num, the odometer reading.
Line 2: an integer k, the window width.
A single integer: the number of resonant windows.
num has no leading zero.Example 1
Input
240 2
Expected
2
Explanation
The 2-digit overlapping windows of "240" are "24" and "40". 240 % 24 = 0 and 240 % 40 = 0, so both windows are resonant, giving a count of 2.
Example 2
Input
125 1
Expected
2
Explanation
The 1-digit windows of "125" are "1", "2", "5". 125 % 1 = 0 and 125 % 5 = 0, but 125 % 2 = 1, so only two of the three windows are resonant.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →