Count the positions in an array where a prefix condition holds after building values by a simple recurrence.
You are given two integers and . Consider an array of length defined by:
Your task is to determine how many positions of the array satisfy a chosen prefix-based condition that can be checked while the array is generated.
This is a lightweight constructive / simulation problem: generate the sequence, track the needed running information, and count the valid positions.
The exact condition is evaluated from the generated array values and the running prefix state, so the intended solution is to process the array from left to right in linear time.
Example 1
Input
5 3
Output
2
Explanation
The sequence is generated step by step using the recurrence. While scanning left to right, two positions satisfy the prefix-based check, so the answer is 2.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.