using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
//using Edge = Pair<long, int>;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
        //WriteLine(Solve());
    }
    static long[] abcd;
    static void Solve()
    {
        abcd = Input.arL;
        var c = calc(abcd[2]);
        var d = calc(abcd[3]);
        var f = calc(Calculation.LCM(abcd[2],abcd[3]));
        WriteLine(abcd[1]-abcd[0]+1-(c + d - f));
    }
    public static long calc(long num)
    {
        var ma = abcd[0] + (num - abcd[0] % num) % num;
        var mb = abcd[1] - abcd[1] % num;
        ma /= num;
        mb /= num;
        return mb - ma + 1;

    }
}

public class Input
{
    public static string read => ReadLine().Trim();
    public static int[] ar => read.Split(' ').Select(int.Parse).ToArray();
    public static int num => ToInt32(read);
    public static long[] arL => read.Split(' ').Select(long.Parse).ToArray();
    public static long numL => ToInt64(read);
    public static char[][] gred(int h)
        => Enumerable.Repeat(0, h).Select(_ => read.ToCharArray()).ToArray();
    public static int[] ar1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => num).ToArray();
    public static long[] arL1D(int n)
        => Enumerable.Repeat(0, n).Select(_ => numL).ToArray();
    public static string[] strs(int n)
        => Enumerable.Repeat(0, n).Select(_ => read).ToArray();
    public static int[][] ar2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => ar).ToArray();
    public static long[][] arL2D(int n)
        => Enumerable.Repeat(0, n).Select(_ => arL).ToArray();
    public static T getValue<T>(string g)
    {
        var t = typeof(T);
        if (t == typeof(int))
            return (T)(object)int.Parse(g);
        if (t == typeof(long))
            return (T)(object)long.Parse(g);
        if (t == typeof(string))
            return (T)(object)g;
        if (t == typeof(char))
            return (T)(object)char.Parse(g);
        if (t == typeof(double))
            return (T)(object)double.Parse(g);
        if (t == typeof(bool))
            return (T)(object)bool.Parse(g);
        return default(T);
    }
    public static string[] Make<T1, T2>(out T1 v1, out T2 v2)
    {
        var r = read.Split(' ');
        v1 = getValue<T1>(r[0]);
        v2 = getValue<T2>(r[1]);
        return r;
    }
    public static string[] Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3)
    {
        var r = Make(out v1, out v2);
        v3 = getValue<T3>(r[2]);
        return r;
    }
    public static string[] Make<T1,T2,T3,T4>(out T1 v1,out T2 v2,out T3 v3,out T4 v4)
    {
        var r = Make(out v1, out v2, out v3);
        v4 = getValue<T4>(r[3]);
        return r;
    }
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public const int MOD = 1000000007;
}

public class Calculation
{
    public static int LCM(int num1, int num2)
        => num1 / GCD(num1, num2) * num2;

    public static long LCM(long num1, long num2)
        => num1 / GCD(num1, num2) * num2;

    public static int GCD(int num1, int num2)
        => num1 < num2 ? GCD(num2, num1) :
           num2 > 0 ? GCD(num2, num1 % num2) : num1;

    public static long GCD(long num1, long num2)
        => num1 < num2 ? GCD(num2, num1) :
           num2 > 0 ? GCD(num2, num1 % num2) : num1;

    public static long[][] E(int num)
    {
        var tm = new long[num][];
        for(var i = 0; i < num; i++) { tm[i] = new long[num];tm[i][i] = 1; }
        return tm;
    }

    public static T[][] trans<T>(T[][] ar)
    {
        var n = ar[0].Length;var m = ar.Length;
        var tm = new T[n][];
        for(var i = 0; i < n; i++)
        {
            tm[i] = new T[m];
            for (var j = 0; j < m; j++)
                tm[i][j] = ar[j][i];
        }
        return tm;
    }

    public static long dot(long[] ar1, long[] ar2)
    {
        var tm = 0L;
        for (var i = 0; i < ar1.Length; i++)
            tm = (tm + ar1[i] * ar2[i]) % Input.MOD;
        return tm;
    }

    public static long[] mul(long[][] ar, long[] ls)
        => ar.Select(a => dot(a, ls)).ToArray();
   
    public static long[][] mul(long[][] ar1,long[][] ar2)
    {
        var bt = trans(ar2);
        return ar1.Select(a => mul(bt, a)).ToArray();
    }

    public static long[][] pow(long[][] A,long n)
    {
        if (n == 0) return E(A.Length);
        var tm = pow(A, n / 2);
        if (n % 2 == 0) return mul(tm, tm);
        else return mul(mul(tm, tm), A);
    }

    public static List<int> PrimeList(long num)
    {
        if (num < 2) return new List<int>();
        var prime = new List<int> { 2 };
        var bo = new bool[num + 1];
        for (var i = 3; i <= num; i += 2)
            if (!bo[i])
            {
                prime.Add(i);
                for (var j = 3 * i; j <= num; j += 2 * i)
                    bo[j] = true;
            }
        return prime;
    }

    public static Dictionary<long,int> Factorize(long num)
    {
        var dic = new Dictionary<long, int>();
        for(var i = 2L; i * i <= num; i++)
        {
            var ct = 0;
            while (num % i == 0)
            {
                ct++;
                num /= i;
            }
            if (ct != 0) dic[i] = ct;
        }
        if (num != 1) dic[num] = 1;
        return dic;
    }
}


Measured memory_bytes: 13396