# codeforces Educational Codeforces Round 16 D. Two Arithmetic Progressions 扩展欧几里得

//1 9 3 11 49 109
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#define lson i<<1
#define rson (i<<1)+1
#define LL long long
#define pi acos(-1.0)
#define mid (l+r)/2
#define maxn 10000005
using namespace std;
LL x,y;
LL e_gcd(LL a, LL b)
{
if(b==0)
{
x = 1;
y = 0;
return a;
}
LL ans = e_gcd(b,a%b);
LL t = x;
x = y;
y = t-a/b*y;
return ans;
}  //求通解
LL a1,b1,a2,b2,l,r;
int main()
{
scanf("%I64d %I64d %I64d %I64d %I64d %I64d", &a1, &b1, &a2, &b2, &l, &r);

//扩展欧几里得求通解
LL a = a1, b = -1 * a2;
LL GCD = e_gcd(a, b);

if((b2 - b1)%GCD != 0) printf("0\n");
else{
//求k左右边界
x *= (b2 - b1)/GCD;
LL add = b / GCD ;
if((l - b1) % a1==0) l = (l - b1) / a1;
else if(l - b1 >= 0)l = (l - b1) / a1 + 1;
else l = (l - b1) / a1 ;

if((r - b1) % a1==0) r = (r - b1) / a1;
else if(r - b1 >= 0)r = (r - b1) / a1;
else r = (r - b1) / a1 - 1;

//根据l>=0的条件刷新边界 且k>=0刷新边界
if(r < 0) { printf("0\n"); return 0; }
if(r * a1 + b1 - b2 < 0) { printf("0\n"); return 0;}
l = max(0ll, l);
if(l * a1 + b1 - b2 < 0)
{
if((b2 - b1) % a1 != 0) l = (b2 - b1) / a1 + 1;
else  l = (b2 - b1) / a1;
}

//求l,r内的解
l-=x;
r-=x;
printf("%I64d\n", max(0ll, (r - l)/add + 1));
}
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120