PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CT0000070. Bội số riêng (Exclusive Multiples)

Bài tập này chưa được xếp vào lộ trình.

Bội số riêng (Exclusive Multiples)

Exclusive Multiples

Version: Phuoc Hung OJ Extended

Problem Statement

Consider all integers in the inclusive interval [L,R][L,R] and two positive integers aa and bb.

An integer xx is an exclusive multiple of aa and bb if it is divisible by exactly one of them: either by aa but not bb, or by bb but not aa. Integers divisible by both, or by neither, are not counted.

Task: Count the integers xx satisfying L≤x≤RL\le x\le R that are exclusive multiples of aa and bb.

Input

One line containing four positive integers LL, RR, aa, and bb, in that order.

Output

Print one integer: the number of exclusive multiples in [L,R][L,R].

Subtasks

  • Subtask 1 (30 points): 1≤L≤R≤1051\le L\le R\le 10^5; 1≤a,b≤1091\le a,b\le 10^9.
  • Subtask 2 (30 points): 1≤L≤R≤10121\le L\le R\le 10^{12}; 1≤a,b≤1091\le a,b\le 10^9.
  • Subtask 3 (40 points): 1≤L≤R≤10181\le L\le R\le 10^{18}; 1≤a,b≤1091\le a,b\le 10^9.

Examples

Example 1

Input

1 30 4 6

Output

8

Explanation

The multiples of 44 in the interval are 4,8,12,16,20,24,284,8,12,16,20,24,28; those of 66 are 6,12,18,24,306,12,18,24,30. Remove 1212 and 2424 because both divisibility conditions hold. Exactly eight numbers remain: 4,6,8,16,18,20,28,304,6,8,16,18,20,28,30.

Example 2

Input

10 20 2 3

Output

5

Explanation

The integers divisible by exactly one of 22 and 33 are 10,14,15,16,2010,14,15,16,20. The integers 1212 and 1818 are multiples of both and therefore excluded.

Example 3

Input

1 12 4 4

Output

0

Explanation

Since a=b=4a=b=4, any multiple of aa is also a multiple of bb. No integer is divisible by exactly one, so the answer is 00.