#abc334b. B - Christmas Trees

B - Christmas Trees

Score : 250250 points

问题描述

在一条无限延伸的东西走向的道路上,从某一特定参考点向东xx米处的一个点的坐标被定义为xx。特别是,从该参考点向西xx米处的点的坐标为x-x

Snuke 将按照每间隔MM米的距离,在从坐标为AA的点开始的道路上设置圣诞树。换句话说,对于可以用整数kk表示为A+kMA+kM的所有点,他将在这些点上设置一棵圣诞树。

Takahashi 和 Aoki 分别站在坐标为LLRR (LR)(L\leq R)的点上。找出在Takahashi和Aoki之间(包括他们所站的位置)将会设置多少棵圣诞树。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There is a road that stretches infinitely to the east and west, and the coordinate of a point located xx meters to the east from a certain reference point on this road is defined as xx. In particular, the coordinate of a point located xx meters to the west from the reference point is x-x.

Snuke will set up Christmas trees at points on the road at intervals of MM meters, starting from a point with coordinate AA. In other words, he will set up a Christmas tree at each point that can be expressed as A+kMA+kM using some integer kk.

Takahashi and Aoki are standing at points with coordinates LL and RR (LR)(L\leq R), respectively. Find the number of Christmas trees that will be set up between Takahashi and Aoki (including the points where they are standing).

Constraints

  • 1018A1018-10^{18}\leq A \leq 10^{18}
  • 1M1091\leq M \leq 10^9
  • 1018LR1018-10^{18}\leq L\leq R \leq 10^{18}
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

AA MM LL RR

Output

Print the number of Christmas trees that will be set up between Takahashi and Aoki (including the points where they are standing).

Sample Input 1

5 3 -1 6

Sample Output 1

3

Snuke will set up Christmas trees at points with coordinates ,4,1,2,5,8,11,14\dots,-4,-1,2,5,8,11,14\dots. Three of them at coordinates 1-1, 22, and 55 are between Takahashi and Aoki.

Sample Input 2

-2 2 1 1

Sample Output 2

0

Sometimes, Takahashi and Aoki are standing at the same point.

Sample Input 3

-177018739841739480 2436426 -80154573737296504 585335723211047198

Sample Output 3

273142010859

update @ 2024/3/10 01:20:56