/**

吉林大学
Jilin U

Author:     sinianluoye (JLU_LiChuang)
Date:        2015-3
Usage:

**/

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define eps 1e-8
#define ms(x,y) (memset(x,y,sizeof(x)))
#define fr(i,x,y) for(int i=x;i<=y;i++)
#define rfr(i,x,y) for(int i=x;i>=y;i--)
#define sqr(x) ((x)*(x))
#define MP(x,y) make_pair(x,y)
#define PB(x) push_back(x)
#define f1 first
#define f2 second
#define DOUBLE_OUTPUT_LENGTH 6
using namespace std;
///const int INF=0x3f3f3f3f;
///const double D_INF=1e100;
///const double C=0.577215664901532860606;//欧拉常数
///const double pi=3.141592653589793238;//圆周率
///const double e=2.71828182845904523536;//自然对数
///const double fai=1.6180339887;//黄金分割数
template<class T>
T gcd(T a,T b){if(!b)return a;while(b^=a^=b^=a%=b);return a;}
template<class T>
T max(const T& t1,const T& t2,const T& t3){return max(max(t1,t2),t3);}
template<class T>
T max(const T& t1,const T& t2,const T& t3,const T& t4)
{return max(max(t1,t2),max(t3,t4));}
ll fpow(ll x,ll y,ll mod=0x7fffffffffffffffll){ll ret=1;while(y){if(y&1)ret*=x,ret%=mod;x*=x;x%=mod;y>>=1;}return ret;}
void ex_gcd(ll a,ll b,ll& x,ll& y){if(b==0){x=a;y=0;return;}ex_gcd(b,a%b,y,x);y=y-a/b*x;}
ll modrev(ll x,ll mod)///乘法逆元
{ll x1,x2;ex_gcd(x,mod,x1,x2);return x1;}
ull T_rand(){return (ull)(rand());}
ull Rand()///返回 0~2^64-1之间的一个随机数
{return (T_rand()<<48)|(T_rand()<<32)|(T_rand()<<16)|T_rand();}
#ifdef LOCAL_USER_SINIANLUOYE
#include <windows.h>
#define OUTCOL SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE)
#define INCOL SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)
#else
#define OUTCOL
#define INCOL
#endif // LOCALE_USER_SINIANLUOYE

template<class T>
bool PRE_INPUT_INTENGER(T& ret)
{INCOL;ret=0;char c=getchar();if(c==-1)return 0;bool f=0;while((c<'0'||c>'9')&&(c!=-1)&&(c!='-'))c=getchar();if(c=='-'){f=1;c=getchar();}while(c>='0'&&c<='9')ret*=10,ret+=c-'0',c=getchar();if(f)ret=-ret;if(c==-1)return 0;return 1;}
bool input(int& ret){return PRE_INPUT_INTENGER(ret);}
bool input(ll& ret){return PRE_INPUT_INTENGER(ret);}
bool input(ull& ret){return PRE_INPUT_INTENGER(ret);}
bool input(unsigned int& ret){return PRE_INPUT_INTENGER(ret);}
template<class T>
bool PRE_INPUT_DOUBLE(T& ret)
{INCOL;ret=0;char c=getchar();if(c==-1)return 0;bool f=0;while((c<'0'||c>'9')&&(c!=-1)&&(c!='.')&&(c!='-'))c=getchar();bool isright=0;
if(c=='-'){f=1;c=getchar();}T t=1;while((c>='0'&&c<='9')||(c=='.')){if(c=='.')isright=1;else{ret*=10,ret+=c-'0';if(isright)t*=10;}c=getchar();}ret/=t;if(f)ret=-ret;if(c==-1)return 0;return 1;}
bool input(double& ret){return PRE_INPUT_DOUBLE(ret);}
bool input(float& ret){return PRE_INPUT_DOUBLE(ret);}
bool IS_SPECIAL_CHAR(const char& ret){return (ret==' '||ret=='\n'||ret=='\t'||ret=='\r'||ret=='\v');}
bool input(char& ret)///注意 用input输入char会滤过空格回车换行制表符
{INCOL;ret=getchar();if(ret==-1)return 0;while(IS_SPECIAL_CHAR(ret))ret=getchar();return ~ret;}
bool input(char* ret)///注意 用input输入char会滤过空格回车换行制表符
{INCOL;char c;if(!input(c))return 0;*ret++=c;while(!IS_SPECIAL_CHAR(*(ret-1)))*ret++=getchar();*(ret-1)=0;return 1;}
template<class T1,class T2>
bool input(T1& t1,T2& t2){return input(t1)&&input(t2);}
template<class T1,class T2,class T3>
bool input(T1& t1,T2& t2,T3& t3){return input(t1)&&input(t2)&&input(t3);}
template<class T1,class T2,class T3,class T4>
bool input(T1& t1,T2& t2,T3& t3,T4& t4){return input(t1)&&input(t2)&&input(t3)&&input(t4);}
template<class T1,class T2,class T3,class T4,class T5>
bool input(T1& t1,T2& t2,T3& t3,T4& t4,T5& t5){return input(t1)&&input(t2)&&input(t3)&&input(t4)&&input(t5);}
template<class T>
void input(T* a, int n){fr(i,0,n-1)input(a[i]);}
template<class T>
void PRE_OUTPUT_INTENGER(const T& t)
{OUTCOL;if(!t){putchar('0');return ;}T key=t;int tt[25];if(key<0){putchar('-');key=-key;}int cnt=0;
while(key)tt[cnt++]=key%10,key/=10;while(cnt)putchar(tt[--cnt]+'0');INCOL;}
void output(const int& t){PRE_OUTPUT_INTENGER(t);}
void output(const ll& t){PRE_OUTPUT_INTENGER(t);}
void output(const ull& t){PRE_OUTPUT_INTENGER(t);}
void output(const unsigned int& t){PRE_OUTPUT_INTENGER(t);}
template<class T>
void PRE_OUTPUT_DOUBLE(const T& key)
{OUTCOL;printf("%.*f",DOUBLE_OUTPUT_LENGTH,key);INCOL;}
void output(const double& t){PRE_OUTPUT_DOUBLE(t);}
void output(const float& t){PRE_OUTPUT_DOUBLE(t);}
void output(const char* ch){OUTCOL;int cnt=0;while(ch[cnt])putchar(ch[cnt++]);INCOL;}
void output(const char& c){OUTCOL;putchar(c);INCOL;}
void output(const string& s){output(s.c_str());}
template<class T1,class T2>
void output(const T1& t1,const T2& t2){output(t1);output(t2);}
template<class T1,class T2,class T3>
void output(const T1& t1,const T2& t2,const T3& t3){output(t1);output(t2);output(t3);}
template<class T1,class T2,class T3,class T4>
void output(const T1& t1,const T2& t2,const T3& t3,const T4& t4){output(t1);output(t2);output(t3);output(t4);}
template<class T1,class T2,class T3,class T4,class T5>
void output(const T1& t1,const T2& t2,const T3& t3,const T4& t4,const T5& t5){output(t1);output(t2);output(t3);output(t4);output(t5);}
template<class T1,class T2,class T3,class T4,class T5,class T6>
void output(const T1& t1,const T2& t2,const T3& t3,const T4& t4,const T5& t5,const T6& t6){output(t1);output(t2);output(t3);output(t4);output(t5);output(t6);}
template<class T1,class T2,class T3,class T4,class T5,class T6,class T7>
void output(const T1& t1,const T2& t2,const T3& t3,const T4& t4,const T5& t5,const T6& t6,const T7& t7){output(t1);output(t2);output(t3);output(t4);output(t5);output(t6);output(t7);}
#define EL putchar('\n')
template<class T>
void printal(T* a,int n)///print a line 在一行中打印数组的0~n-1空格分割结尾换行
{for(int i=0;i<n-1;i++)output(a[i],' ');output(a[n-1],'\n');}
template<class T>
void printel(T* a,int n)///print every line 在每行中打印数组的0~n-1 每行一个元素
{for(int i=0;i<n;i++)output(a[i],'\n');}
template<class T>
void inputal(T* a, int n){fr(i,0,n-1)input(a[i]);}
/**------------------------------------------------------分割线 下边写代码-------------------------------------------------------------**/

ll count_div(ll a, ll b, ll d) {
    return b / d - (a-1) / d;
}

int main()
{
    #ifdef LOCAL_USER_SINIANLUOYE
//    freopen("input.txt", "r", stdin);
    #endif // LOCAL_USER_SINIANLUOYE
    ll a, b, c, d;
    input(a, b, c, d);
    ll lcm = c / gcd(c, d) * d;
//    output(count_div(2,4,2));
    output(b - a + 1 - count_div(a, b, c) - count_div(a, b, d) + count_div(a, b, lcm));EL;

}

/*************copyright by sinianluoye (JLU_LiChuang)***********/


Measured memory_bytes: 256