EtashGuha's picture
Add files using upload-large-folder tool
3cee1f8 verified
|
raw
history blame
869 Bytes

710_D. Two Arithmetic Progressions

Problem Description

You are given two arithmetic progressions: a1k + b1 and a2l + b2. Find the number of integers x such that L ≤ x ≤ R and x = a1k' + b1 = a2l' + b2, for some integers k', l' ≥ 0.

Input

The only line contains six integers a1, b1, a2, b2, L, R (0 < a1, a2 ≤ 2·109, - 2·109 ≤ b1, b2, L, R ≤ 2·109, L ≤ R).

Output

Print the desired number of integers x.

Examples

Input

2 0 3 3 5 21

Output

3

Input

2 4 3 0 6 17

Output

2

Contest Information

  • Contest ID: 710
  • Problem Index: D
  • Points: 0.0
  • Rating: 2500
  • Tags: math, number theory
  • Time Limit: {'seconds': 1, 'nanos': 0} seconds
  • Memory Limit: 256000000 bytes

Task

Solve this competitive programming problem. Provide a complete solution that handles all the given constraints and edge cases.