2187.Two Arithmetic Progressions

Time Limit: 1s Memory Limit: 256MB

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

Input Format(From the terminal/stdin)

The only line contains six integers a1,b1,a2,b2,L,R (0 \lt a1,a2 \le 2 \cdot 109,-2 \cdot 109 \le b1,b2,L,R \le 2 \cdot 109,L \le R).

Output Format(To the terminal/stdout)

Print the desired number of integers x.

Sample Input 1

Copy
2 0 3 3 5 21
 · · · · ·  \n

Sample Output 1

Copy
3
 \n

Sample Input 2

Copy
2 4 3 0 6 17
 · · · · ·  \n

Sample Output 2

Copy
2
 \n

Submit

请先 登录

© 2025 FAQs