QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100

#24424. Malfunctioning Mars Rover

统计

A rover carrying out an international mission on Mars has malfunctioned. To restore its operation, its battery power must be increased.

The rover’s battery power is a positive integer. Its current power is $a$, and to restore the rover’s operation it must be increased to $b$. To change the battery power, special signals of two types, X and Y, can be sent to the rover from Earth. An X signal increases the current battery power by $1$, while a Y signal increases it by $2$.

The mission organizers would like to reach the required battery power by sending as few signals as possible. Unfortunately, because of the rover’s design, if its battery power becomes a multiple of the integer $c$, the rover fails permanently and stops responding to signals.

Write a program that, given the initial battery power $a$, the required battery power $b$, and the integer $c$, determines the minimum number of signals that must be sent to the rover to restore its operation.

Input

The input contains three integers, $a$, $b$, and $c$, one per line ($1 \le a < b \le 10^9$, $2 \le c \le 10^9$; neither $a$ nor $b$ is a multiple of $c$).

Output

Output one integer: the minimum number of signals that must be sent to the rover.

Examples

Input 1

2
7
3

Output 1

3

Input 2

4
10
3

Output 2

4

Note

In the first example, one can send the signals Y, X, Y to the rover. The battery power changes as follows: $2 \to 4 \to 5 \to 7$.

In the second example, one can send the signals X, Y, X, Y to the rover. The battery power changes as follows: $4 \to 5 \to 7 \to 8 \to 10$.

Subtasks

Points for a subtask are awarded only if all tests for that subtask and its required subtasks are passed.

Subtask Points Constraints Required subtasks Feedback
1 25 $1 \le a < b \le 15$, $2 \le c \le 15$ full
2 25 $1 \le a < b \le 10^5$, $2 \le c \le 10^5$ 1 full
3 25 $1 \le a < b \le 10^9$, $c=2$ full
4 25 $1 \le a < b \le 10^9$, $2 \le c \le 10^9$ 1, 2, 3 full

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.