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

#CT0000144. Hai lịch trực (Two Duty Schedules)

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

Hai lịch trực (Two Duty Schedules)

Two Duty Schedules

Version: Phuoc Hung OJ Extended

Problem Statement

At a library, two volunteer groups follow fixed duty schedules. Days are numbered by positive integers starting from 11.

Group A is on duty on days whose numbers are divisible by aa. Group B is on duty on days whose numbers are divisible by bb. Their schedules are independent, so both groups may be on duty on the same day.

Count the days in the inclusive interval [l,r][l,r] on which exactly one of the two groups is on duty. Days with neither group or with both groups must not be counted.

Input

A single line contains four positive integers ll, rr, aa, bb, in that order.

Output

Print one integer: the number of days in [l,r][l,r] on which exactly one group is on duty.

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≤1091\le l\le r\le 10^9; 1≤a,b≤1091\le a,b\le 10^9.
  • Subtask 3 (40 points): 1≤l≤r≤10121\le l\le r\le 10^{12}; 1≤a,b≤1091\le a,b\le 10^9.

Examples

Example 1

Input

1 20 4 6

Output

6

Explanation

Group A attends on days 4,8,12,16,204,8,12,16,20 and group B on 6,12,186,12,18. Day 1212 belongs to both schedules and must be excluded. Exactly six days remain: 4,6,8,16,18,204,6,8,16,18,20.

Example 2

Input

5 15 3 3

Output

0

Explanation

Both periods are 33. Every day divisible by 33 in [5,15][5,15] has both groups on duty, and all other days have neither group. Hence the answer is 00.

Example 3

Input

10 30 4 7

Output

6

Explanation

Multiples of 44 in the interval are 12,16,20,24,2812,16,20,24,28; multiples of 77 are 14,21,2814,21,28. Day 2828 is shared and excluded. The valid days are 12,14,16,20,21,2412,14,16,20,21,24, giving 66.