import java.util.Scanner;

public class Main{
    static long lcm (long a, long b) {
	     long temp;
	      long c = a;
	       c *= b;
	        while((temp = a%b)!=0) {
  		        a = b;
		            b = temp;
  	           }
	     return (long)(c/b);
     }

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    long a=scanner.nextLong();
    long b=scanner.nextLong();
    long c=scanner.nextLong();
    long d=scanner.nextLong();
    //int a[]=new int[n];

    //System.out.println(a);
    long bc,bd,ac,ad;
    bc=b/c;
    bd=b/d;
    ac=(a-1)/c;
    ad=(a-1)/d;
    long num1,num2;
    num1=bc-ac;
    num2=bd-ad;
    long scd;
    long bscd,ascd;
    scd=lcm(c,d);
    bscd=b/scd;
    ascd=(a-1)/scd;
    long num3;
    num3=bscd-ascd;

    long cnt=b-a+1-num1-num2+num3;
    //System.out.println(b+"-"+a+"-"+num1+"-"+num2+"+"+num3);
    System.out.println(cnt);
  }
} import java.util.Scanner; Scanner java.util public class Main{
    static long lcm (long a, long b) {
	     long temp;
	      long c = a;
	       c *= b;
	        while((temp = a%b)!=0) {
  		        a = b;
		            b = temp;
  	           }
	     return (long)(c/b);
     }

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    long a=scanner.nextLong();
    long b=scanner.nextLong();
    long c=scanner.nextLong();
    long d=scanner.nextLong();
    //int a[]=new int[n];

    //System.out.println(a);
    long bc,bd,ac,ad;
    bc=b/c;
    bd=b/d;
    ac=(a-1)/c;
    ad=(a-1)/d;
    long num1,num2;
    num1=bc-ac;
    num2=bd-ad;
    long scd;
    long bscd,ascd;
    scd=lcm(c,d);
    bscd=b/scd;
    ascd=(a-1)/scd;
    long num3;
    num3=bscd-ascd;

    long cnt=b-a+1-num1-num2+num3;
    //System.out.println(b+"-"+a+"-"+num1+"-"+num2+"+"+num3);
    System.out.println(cnt);
  }
} Main static long lcm (long a, long b) {
	     long temp;
	      long c = a;
	       c *= b;
	        while((temp = a%b)!=0) {
  		        a = b;
		            b = temp;
  	           }
	     return (long)(c/b);
     } lcm {
	     long temp;
	      long c = a;
	       c *= b;
	        while((temp = a%b)!=0) {
  		        a = b;
		            b = temp;
  	           }
	     return (long)(c/b);
     } long temp; temp long c = a; c a c *= b c b while((temp = a%b)!=0) {
  		        a = b;
		            b = temp;
  	           } (temp = a%b)!=0 (temp = a%b) temp a%b a b 0 {
  		        a = b;
		            b = temp;
  	           } a = b a b b = temp b temp return (long)(c/b); (long)(c/b) c b long a a long b b public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    long a=scanner.nextLong();
    long b=scanner.nextLong();
    long c=scanner.nextLong();
    long d=scanner.nextLong();
    //int a[]=new int[n];

    //System.out.println(a);
    long bc,bd,ac,ad;
    bc=b/c;
    bd=b/d;
    ac=(a-1)/c;
    ad=(a-1)/d;
    long num1,num2;
    num1=bc-ac;
    num2=bd-ad;
    long scd;
    long bscd,ascd;
    scd=lcm(c,d);
    bscd=b/scd;
    ascd=(a-1)/scd;
    long num3;
    num3=bscd-ascd;

    long cnt=b-a+1-num1-num2+num3;
    //System.out.println(b+"-"+a+"-"+num1+"-"+num2+"+"+num3);
    System.out.println(cnt);
  } main {
    Scanner scanner = new Scanner(System.in);
    long a=scanner.nextLong();
    long b=scanner.nextLong();
    long c=scanner.nextLong();
    long d=scanner.nextLong();
    //int a[]=new int[n];

    //System.out.println(a);
    long bc,bd,ac,ad;
    bc=b/c;
    bd=b/d;
    ac=(a-1)/c;
    ad=(a-1)/d;
    long num1,num2;
    num1=bc-ac;
    num2=bd-ad;
    long scd;
    long bscd,ascd;
    scd=lcm(c,d);
    bscd=b/scd;
    ascd=(a-1)/scd;
    long num3;
    num3=bscd-ascd;

    long cnt=b-a+1-num1-num2+num3;
    //System.out.println(b+"-"+a+"-"+num1+"-"+num2+"+"+num3);
    System.out.println(cnt);
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) long a=scanner.nextLong(); a scanner.nextLong() scanner.nextLong scanner long b=scanner.nextLong(); b scanner.nextLong() scanner.nextLong scanner long c=scanner.nextLong(); c scanner.nextLong() scanner.nextLong scanner long d=scanner.nextLong(); d scanner.nextLong() scanner.nextLong scanner long bc bc bd bd ac ac ad; ad bc=b/c bc b/c b c bd=b/d bd b/d b d ac=(a-1)/c ac (a-1)/c (a-1) a 1 c ad=(a-1)/d ad (a-1)/d (a-1) a 1 d long num1 num1 num2; num2 num1=bc-ac num1 bc-ac bc ac num2=bd-ad num2 bd-ad bd ad long scd; scd long bscd bscd ascd; ascd scd=lcm(c,d) scd lcm(c,d) lcm c d bscd=b/scd bscd b/scd b scd ascd=(a-1)/scd ascd (a-1)/scd (a-1) a 1 scd long num3; num3 num3=bscd-ascd num3 bscd-ascd bscd ascd long cnt=b-a+1-num1-num2+num3; cnt b-a+1-num1-num2+num3 b-a+1-num1-num2 b-a+1-num1-num2 b-a+1 b-a b a 1 num1 num2 num3 System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main{
    static long lcm (long a, long b) {
	     long temp;
	      long c = a;
	       c *= b;
	        while((temp = a%b)!=0) {
  		        a = b;
		            b = temp;
  	           }
	     return (long)(c/b);
     }

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    long a=scanner.nextLong();
    long b=scanner.nextLong();
    long c=scanner.nextLong();
    long d=scanner.nextLong();
    //int a[]=new int[n];

    //System.out.println(a);
    long bc,bd,ac,ad;
    bc=b/c;
    bd=b/d;
    ac=(a-1)/c;
    ad=(a-1)/d;
    long num1,num2;
    num1=bc-ac;
    num2=bd-ad;
    long scd;
    long bscd,ascd;
    scd=lcm(c,d);
    bscd=b/scd;
    ascd=(a-1)/scd;
    long num3;
    num3=bscd-ascd;

    long cnt=b-a+1-num1-num2+num3;
    //System.out.println(b+"-"+a+"-"+num1+"-"+num2+"+"+num3);
    System.out.println(cnt);
  }
} public class Main{
    static long lcm (long a, long b) {
	     long temp;
	      long c = a;
	       c *= b;
	        while((temp = a%b)!=0) {
  		        a = b;
		            b = temp;
  	           }
	     return (long)(c/b);
     }

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    long a=scanner.nextLong();
    long b=scanner.nextLong();
    long c=scanner.nextLong();
    long d=scanner.nextLong();
    //int a[]=new int[n];

    //System.out.println(a);
    long bc,bd,ac,ad;
    bc=b/c;
    bd=b/d;
    ac=(a-1)/c;
    ad=(a-1)/d;
    long num1,num2;
    num1=bc-ac;
    num2=bd-ad;
    long scd;
    long bscd,ascd;
    scd=lcm(c,d);
    bscd=b/scd;
    ascd=(a-1)/scd;
    long num3;
    num3=bscd-ascd;

    long cnt=b-a+1-num1-num2+num3;
    //System.out.println(b+"-"+a+"-"+num1+"-"+num2+"+"+num3);
    System.out.println(cnt);
  }
} Main
import java.util.Scanner;

public class Main{
    static long lcm (long a, long b) {
	     long temp;
	      long c = a;
	       c *= b;
	        while((temp = a%b)!=0) {
  		        a = b;
		            b = temp;
  	           }
	     return (long)(c/b);
     }

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    long a=scanner.nextLong();
    long b=scanner.nextLong();
    long c=scanner.nextLong();
    long d=scanner.nextLong();
    //int a[]=new int[n];

    //System.out.println(a);
    long bc,bd,ac,ad;
    bc=b/c;
    bd=b/d;
    ac=(a-1)/c;
    ad=(a-1)/d;
    long num1,num2;
    num1=bc-ac;
    num2=bd-ad;
    long scd;
    long bscd,ascd;
    scd=lcm(c,d);
    bscd=b/scd;
    ascd=(a-1)/scd;
    long num3;
    num3=bscd-ascd;

    long cnt=b-a+1-num1-num2+num3;
    //System.out.println(b+"-"+a+"-"+num1+"-"+num2+"+"+num3);
    System.out.println(cnt);
  }
}
