import java.util.*;
public class Main
{
    public static long findGCD(long c,long d)
    {
        if (d != 0)
       return findGCD(d, c%d);
    else 
       return c;
    }
  public static void main(String[] args)
  {
    Scanner Sc=new Scanner(System.in);
    long a=Sc.nextLong();
    long b=Sc.nextLong();
    long c=Sc.nextInt();
    long d=Sc.nextInt();
    long g=findGCD(c,d);
    long l=(c*d)/g;
    long mc=(b/c)-((a-1)/c);
    long md=(b/d)-((a-1)/d);
    long ml=(b/l)-((a-1)/l);
    System.out.println((b-a+1)-(mc+md)+ml);
  }
} import java.util.*; util.* java public class Main
{
    public static long findGCD(long c,long d)
    {
        if (d != 0)
       return findGCD(d, c%d);
    else 
       return c;
    }
  public static void main(String[] args)
  {
    Scanner Sc=new Scanner(System.in);
    long a=Sc.nextLong();
    long b=Sc.nextLong();
    long c=Sc.nextInt();
    long d=Sc.nextInt();
    long g=findGCD(c,d);
    long l=(c*d)/g;
    long mc=(b/c)-((a-1)/c);
    long md=(b/d)-((a-1)/d);
    long ml=(b/l)-((a-1)/l);
    System.out.println((b-a+1)-(mc+md)+ml);
  }
} Main public static long findGCD(long c,long d)
    {
        if (d != 0)
       return findGCD(d, c%d);
    else 
       return c;
    } findGCD {
        if (d != 0)
       return findGCD(d, c%d);
    else 
       return c;
    } if (d != 0)
       return findGCD(d, c%d);
    else 
       return c; d != 0 d 0 return findGCD(d, c%d); findGCD(d, c%d) findGCD d c%d c d return c; c long c c long d d public static void main(String[] args)
  {
    Scanner Sc=new Scanner(System.in);
    long a=Sc.nextLong();
    long b=Sc.nextLong();
    long c=Sc.nextInt();
    long d=Sc.nextInt();
    long g=findGCD(c,d);
    long l=(c*d)/g;
    long mc=(b/c)-((a-1)/c);
    long md=(b/d)-((a-1)/d);
    long ml=(b/l)-((a-1)/l);
    System.out.println((b-a+1)-(mc+md)+ml);
  } main {
    Scanner Sc=new Scanner(System.in);
    long a=Sc.nextLong();
    long b=Sc.nextLong();
    long c=Sc.nextInt();
    long d=Sc.nextInt();
    long g=findGCD(c,d);
    long l=(c*d)/g;
    long mc=(b/c)-((a-1)/c);
    long md=(b/d)-((a-1)/d);
    long ml=(b/l)-((a-1)/l);
    System.out.println((b-a+1)-(mc+md)+ml);
  } Scanner Sc=new Scanner(System.in); Sc new Scanner(System.in) long a=Sc.nextLong(); a Sc.nextLong() Sc.nextLong Sc long b=Sc.nextLong(); b Sc.nextLong() Sc.nextLong Sc long c=Sc.nextInt(); c Sc.nextInt() Sc.nextInt Sc long d=Sc.nextInt(); d Sc.nextInt() Sc.nextInt Sc long g=findGCD(c,d); g findGCD(c,d) findGCD c d long l=(c*d)/g; l (c*d)/g (c*d) c d g long mc=(b/c)-((a-1)/c); mc (b/c)-((a-1)/c) (b/c) b c ((a-1)/c) (a-1) a 1 c long md=(b/d)-((a-1)/d); md (b/d)-((a-1)/d) (b/d) b d ((a-1)/d) (a-1) a 1 d long ml=(b/l)-((a-1)/l); ml (b/l)-((a-1)/l) (b/l) b l ((a-1)/l) (a-1) a 1 l System.out.println((b-a+1)-(mc+md)+ml) System.out.println System.out System System.out (b-a+1)-(mc+md)+ml (b-a+1)-(mc+md) (b-a+1) b-a b a 1 (mc+md) mc md ml String[] args args public class Main
{
    public static long findGCD(long c,long d)
    {
        if (d != 0)
       return findGCD(d, c%d);
    else 
       return c;
    }
  public static void main(String[] args)
  {
    Scanner Sc=new Scanner(System.in);
    long a=Sc.nextLong();
    long b=Sc.nextLong();
    long c=Sc.nextInt();
    long d=Sc.nextInt();
    long g=findGCD(c,d);
    long l=(c*d)/g;
    long mc=(b/c)-((a-1)/c);
    long md=(b/d)-((a-1)/d);
    long ml=(b/l)-((a-1)/l);
    System.out.println((b-a+1)-(mc+md)+ml);
  }
} public class Main
{
    public static long findGCD(long c,long d)
    {
        if (d != 0)
       return findGCD(d, c%d);
    else 
       return c;
    }
  public static void main(String[] args)
  {
    Scanner Sc=new Scanner(System.in);
    long a=Sc.nextLong();
    long b=Sc.nextLong();
    long c=Sc.nextInt();
    long d=Sc.nextInt();
    long g=findGCD(c,d);
    long l=(c*d)/g;
    long mc=(b/c)-((a-1)/c);
    long md=(b/d)-((a-1)/d);
    long ml=(b/l)-((a-1)/l);
    System.out.println((b-a+1)-(mc+md)+ml);
  }
} Main
import java.util.*;
public class Main
{
    public static long findGCD(long c,long d)
    {
        if (d != 0)
       return findGCD(d, c%d);
    else 
       return c;
    }
  public static void main(String[] args)
  {
    Scanner Sc=new Scanner(System.in);
    long a=Sc.nextLong();
    long b=Sc.nextLong();
    long c=Sc.nextInt();
    long d=Sc.nextInt();
    long g=findGCD(c,d);
    long l=(c*d)/g;
    long mc=(b/c)-((a-1)/c);
    long md=(b/d)-((a-1)/d);
    long ml=(b/l)-((a-1)/l);
    System.out.println((b-a+1)-(mc+md)+ml);
  }
}
