import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        Long a = Long.parseLong(line1[0]);
        Long b = Long.parseLong(line1[1]);
        Long c = Long.parseLong(line1[2]);
        Long d = Long.parseLong(line1[3]);
        Long count1 = b - a + 1;
        //System.out.println(count1);
        Long e;
        if(a % c == 0)
        e = a / c;
        else
        e = a / c + 1;
        Long f = b / c;
        Long count2 = f - e + 1;
        //System.out.println(count2);
        if(a % d == 0)
        e = a / d;
        else
        e = a / d + 1;
        f = b / d;
        Long count3 = f - e + 1;
        //System.out.println(count3);
        Long g = lcm(c, d);
        if(a % g == 0)
        e = a / g;
        else
        e = a / g + 1;
        f = b / g;
        Long count4 = f - e + 1;
        //System.out.println(count4);
        System.out.println(count1 - (count2 + count3 - count4));
    }
    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);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        Long a = Long.parseLong(line1[0]);
        Long b = Long.parseLong(line1[1]);
        Long c = Long.parseLong(line1[2]);
        Long d = Long.parseLong(line1[3]);
        Long count1 = b - a + 1;
        //System.out.println(count1);
        Long e;
        if(a % c == 0)
        e = a / c;
        else
        e = a / c + 1;
        Long f = b / c;
        Long count2 = f - e + 1;
        //System.out.println(count2);
        if(a % d == 0)
        e = a / d;
        else
        e = a / d + 1;
        f = b / d;
        Long count3 = f - e + 1;
        //System.out.println(count3);
        Long g = lcm(c, d);
        if(a % g == 0)
        e = a / g;
        else
        e = a / g + 1;
        f = b / g;
        Long count4 = f - e + 1;
        //System.out.println(count4);
        System.out.println(count1 - (count2 + count3 - count4));
    }
    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);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        Long a = Long.parseLong(line1[0]);
        Long b = Long.parseLong(line1[1]);
        Long c = Long.parseLong(line1[2]);
        Long d = Long.parseLong(line1[3]);
        Long count1 = b - a + 1;
        //System.out.println(count1);
        Long e;
        if(a % c == 0)
        e = a / c;
        else
        e = a / c + 1;
        Long f = b / c;
        Long count2 = f - e + 1;
        //System.out.println(count2);
        if(a % d == 0)
        e = a / d;
        else
        e = a / d + 1;
        f = b / d;
        Long count3 = f - e + 1;
        //System.out.println(count3);
        Long g = lcm(c, d);
        if(a % g == 0)
        e = a / g;
        else
        e = a / g + 1;
        f = b / g;
        Long count4 = f - e + 1;
        //System.out.println(count4);
        System.out.println(count1 - (count2 + count3 - count4));
    } main {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        Long a = Long.parseLong(line1[0]);
        Long b = Long.parseLong(line1[1]);
        Long c = Long.parseLong(line1[2]);
        Long d = Long.parseLong(line1[3]);
        Long count1 = b - a + 1;
        //System.out.println(count1);
        Long e;
        if(a % c == 0)
        e = a / c;
        else
        e = a / c + 1;
        Long f = b / c;
        Long count2 = f - e + 1;
        //System.out.println(count2);
        if(a % d == 0)
        e = a / d;
        else
        e = a / d + 1;
        f = b / d;
        Long count3 = f - e + 1;
        //System.out.println(count3);
        Long g = lcm(c, d);
        if(a % g == 0)
        e = a / g;
        else
        e = a / g + 1;
        f = b / g;
        Long count4 = f - e + 1;
        //System.out.println(count4);
        System.out.println(count1 - (count2 + count3 - count4));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc String[] line1 = line.split(" "); line1 line.split(" ") line.split line " " Long a = Long.parseLong(line1[0]); a Long.parseLong(line1[0]) Long.parseLong Long line1[0] line1 0 Long b = Long.parseLong(line1[1]); b Long.parseLong(line1[1]) Long.parseLong Long line1[1] line1 1 Long c = Long.parseLong(line1[2]); c Long.parseLong(line1[2]) Long.parseLong Long line1[2] line1 2 Long d = Long.parseLong(line1[3]); d Long.parseLong(line1[3]) Long.parseLong Long line1[3] line1 3 Long count1 = b - a + 1; count1 b - a + 1 b - a b a 1 Long e; e if(a % c == 0)
        e = a / c;
        else
        e = a / c + 1; a % c == 0 a % c a c 0 e = a / c e a / c a c e = a / c + 1 e a / c + 1 a / c a c 1 Long f = b / c; f b / c b c Long count2 = f - e + 1; count2 f - e + 1 f - e f e 1 if(a % d == 0)
        e = a / d;
        else
        e = a / d + 1; a % d == 0 a % d a d 0 e = a / d e a / d a d e = a / d + 1 e a / d + 1 a / d a d 1 f = b / d f b / d b d Long count3 = f - e + 1; count3 f - e + 1 f - e f e 1 Long g = lcm(c, d); g lcm(c, d) lcm c d if(a % g == 0)
        e = a / g;
        else
        e = a / g + 1; a % g == 0 a % g a g 0 e = a / g e a / g a g e = a / g + 1 e a / g + 1 a / g a g 1 f = b / g f b / g b g Long count4 = f - e + 1; count4 f - e + 1 f - e f e 1 System.out.println(count1 - (count2 + count3 - count4)) System.out.println System.out System System.out count1 - (count2 + count3 - count4) count1 (count2 + count3 - count4) count2 + count3 count2 count3 count4 String[] args args 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 class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        Long a = Long.parseLong(line1[0]);
        Long b = Long.parseLong(line1[1]);
        Long c = Long.parseLong(line1[2]);
        Long d = Long.parseLong(line1[3]);
        Long count1 = b - a + 1;
        //System.out.println(count1);
        Long e;
        if(a % c == 0)
        e = a / c;
        else
        e = a / c + 1;
        Long f = b / c;
        Long count2 = f - e + 1;
        //System.out.println(count2);
        if(a % d == 0)
        e = a / d;
        else
        e = a / d + 1;
        f = b / d;
        Long count3 = f - e + 1;
        //System.out.println(count3);
        Long g = lcm(c, d);
        if(a % g == 0)
        e = a / g;
        else
        e = a / g + 1;
        f = b / g;
        Long count4 = f - e + 1;
        //System.out.println(count4);
        System.out.println(count1 - (count2 + count3 - count4));
    }
    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 class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        Long a = Long.parseLong(line1[0]);
        Long b = Long.parseLong(line1[1]);
        Long c = Long.parseLong(line1[2]);
        Long d = Long.parseLong(line1[3]);
        Long count1 = b - a + 1;
        //System.out.println(count1);
        Long e;
        if(a % c == 0)
        e = a / c;
        else
        e = a / c + 1;
        Long f = b / c;
        Long count2 = f - e + 1;
        //System.out.println(count2);
        if(a % d == 0)
        e = a / d;
        else
        e = a / d + 1;
        f = b / d;
        Long count3 = f - e + 1;
        //System.out.println(count3);
        Long g = lcm(c, d);
        if(a % g == 0)
        e = a / g;
        else
        e = a / g + 1;
        f = b / g;
        Long count4 = f - e + 1;
        //System.out.println(count4);
        System.out.println(count1 - (count2 + count3 - count4));
    }
    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);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        String[] line1 = line.split(" ");
        Long a = Long.parseLong(line1[0]);
        Long b = Long.parseLong(line1[1]);
        Long c = Long.parseLong(line1[2]);
        Long d = Long.parseLong(line1[3]);
        Long count1 = b - a + 1;
        //System.out.println(count1);
        Long e;
        if(a % c == 0)
        e = a / c;
        else
        e = a / c + 1;
        Long f = b / c;
        Long count2 = f - e + 1;
        //System.out.println(count2);
        if(a % d == 0)
        e = a / d;
        else
        e = a / d + 1;
        f = b / d;
        Long count3 = f - e + 1;
        //System.out.println(count3);
        Long g = lcm(c, d);
        if(a % g == 0)
        e = a / g;
        else
        e = a / g + 1;
        f = b / g;
        Long count4 = f - e + 1;
        //System.out.println(count4);
        System.out.println(count1 - (count2 + count3 - count4));
    }
    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);
    }
}