Repovive
  • Dashboard
  • Ranking
  • Submissions
  • Discussion
  1. Contests
  2. Starter Round 6
  3. 19A

My submissions

/
/
/
/

Announcements

My submissions

/
/
/
/

Announcements

Solve
Author

19A. Remainder Count

500 pts·1s·256 MB

Constraints

Input

Output

Samples

Input
10 3 1
Explanation
Output
4
Input
5 7 6
Explanation
Output
0
Input
8 4 0
Explanation
Output
3

You are given three integers nnn, ddd, and rrr.

Count the integers xxx that satisfy both of the following conditions:

  • 0≤x≤n0 \le x \le n0≤x≤n;
  • the remainder when xxx is divided by ddd is rrr.
  • 1≤n,d≤1091 \le n,d \le 10^91≤n,d≤109
  • 0≤r<d0 \le r < d0≤r<d

The input contains three integers nnn, ddd, and rrr.

ndrn \quad d \quad rndr

Output the number of integers xxx that satisfy the given conditions.

answeransweranswer

The valid integers are 111, 444, 777, and 101010, so the answer is 444.

The smallest non-negative integer with remainder 666 after division by 777 is 666, which is greater than 555. Therefore, no valid integer exists.

The valid integers are 000, 444, and 888, so the answer is 333.