跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F1108. Two Arithmetic Progressions

  • ID: 1114
  • 传统题
  • 2000ms
  • 256MiB
  • 尝试: 0
  • AC · 已通过: 0
  • 教学难度:挑战
  • 上传者:
  • 数学
  • 数论
  • 挑战
  • 难度
  • 共享题库
  • Codeforces
  • 英文题面
  • 题目来源
  • 题面语言

Two Arithmetic Progressions

题目描述

D. Two Arithmetic Progressions
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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


题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 575 题。保留原作者与原赛事署名。