Counting not Divisible

View as PDF

Submit solution

Points: 1.00
Time limit: 1.0s
Memory limit: 512M
Input: stdin
Output: stdout

Author:
Problem types

Attempt

Please login to see your submissions result.


Last updated: on Dec. 17, 2024, 8:31 a.m.

Problem

Given four integers ~A, B, C, D~. How many numbers ~X~ that ~X~ satisfied with condition:

  • ~A \leq X \leq B~.
  • ~X~ not divisible by ~C~ or not divisible.

Input

Single line contains four integers ~A, B, C, D~ seperated by spaces.

Output

The number of ~X~ that satisfied with condition.

Constraints

~1 \leq A \leq B \leq 10^{18}~.
~1 \leq C, D \leq 10^9~.

Sample

Sample Input Sample Output
4 9 2 3
2
3 10 4 5
4

Explanation

In the Sample test #1, we have ~2~ number satisfied with condition is ~5, 7~.

In the Sample test #2, we have ~4~ number satisfied with condition is ~3, 6, 7, 9~.


Comments

Please read the guidelines before commenting.


There are no comments at the moment.