Skip to main content
Back to problems
Codeforces
Easy
Arrays
Math
Eugeny and Array

Count the positions in an array where a prefix condition holds after building values by a simple recurrence.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Problem

You are given two integers nn and xx. Consider an array aa of length nn defined by:

  • a1=xa_1 = x
  • for every i>1i > 1, ai=(ai1+x)mod10a_i = (a_{i-1} + x) \bmod 10

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 nn and xx.
  • nn is the array length.
  • xx 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

  • 1n1 \le n is small enough for linear simulation.
  • xx is a non-negative integer.
  • The generated values are taken modulo $10$.
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.