题解
// Problem: C. Lucky Days
// Contest: Codeforces - Mail.Ru Cup 2018 Round 2
// URL: https://codeforces.com/problemset/problem/1055/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
int main(){
int la,ra,ta,lb,rb,tb;
cin>>la>>ra>>ta>>lb>>rb>>tb;
int num=__gcd(ta,tb);
if(la<lb) swap(la,lb),swap(ra,rb);
int sum=la-lb;
lb=lb+sum/num*num;
rb=rb+sum/num*num;
int ans=max(0,min(rb,ra)-max(la-1,lb-1));
lb+=num;rb+=num;
ans=max(ans,min(ra,rb)-max(la-1,lb-1));
cout<<ans<<endl;
return 0;
}