Count the positions in an array where a prefix condition holds after building values by a simple recurrence.
Problem
You are given two integers and . Consider an array of length defined by:
- for every ,
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.
Notes
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.
Input Format
- A single line contains two integers and .
- is the array length.
- is the starting value / step value used to generate the sequence.
Output Format
- Print one integer: the number of positions that satisfy the required condition.
Constraints
- is small enough for linear simulation.
- is a non-negative integer.
- The generated values are taken modulo $10$.
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
Unlock deeper context for this problem
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.