import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long cntA = 0;
        long cntB = 0;
        long lcm = lcm(c, d);

  
        cntA = a - a / c - a / d + a / lcm(c, d);
        cntB = b - b / c - b / d + b / lcm(c, d);
 
        long res = (cntB - cntA);
        if(a % c != 0 && a % d != 0) res++;
        System.out.println(res);
    }

    private static long gcd(long a, long b) {
    	if(b == 0)
    		return a;
    	return gcd(b, a % b);
    }

    private static long lcm(long a, long b) {
    	return a / gcd(a, b) * b;
    }

}

 import java.util.*; util.* java public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long cntA = 0;
        long cntB = 0;
        long lcm = lcm(c, d);

  
        cntA = a - a / c - a / d + a / lcm(c, d);
        cntB = b - b / c - b / d + b / lcm(c, d);
 
        long res = (cntB - cntA);
        if(a % c != 0 && a % d != 0) res++;
        System.out.println(res);
    }

    private static long gcd(long a, long b) {
    	if(b == 0)
    		return a;
    	return gcd(b, a % b);
    }

    private static long lcm(long a, long b) {
    	return a / gcd(a, b) * b;
    }

} Main public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long cntA = 0;
        long cntB = 0;
        long lcm = lcm(c, d);

  
        cntA = a - a / c - a / d + a / lcm(c, d);
        cntB = b - b / c - b / d + b / lcm(c, d);
 
        long res = (cntB - cntA);
        if(a % c != 0 && a % d != 0) res++;
        System.out.println(res);
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long cntA = 0;
        long cntB = 0;
        long lcm = lcm(c, d);

  
        cntA = a - a / c - a / d + a / lcm(c, d);
        cntB = b - b / c - b / d + b / lcm(c, d);
 
        long res = (cntB - cntA);
        if(a % c != 0 && a % d != 0) res++;
        System.out.println(res);
    } 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.nextLong(); c sc.nextLong() sc.nextLong sc long d = sc.nextLong(); d sc.nextLong() sc.nextLong sc long cntA = 0; cntA 0 long cntB = 0; cntB 0 long lcm = lcm(c, d); lcm lcm(c, d) lcm c d cntA = a - a / c - a / d + a / lcm(c, d) cntA a - a / c - a / d + a / lcm(c, d) a - a / c - a / d a - a / c - a / d a a / c a c a / d a d a / lcm(c, d) a lcm(c, d) lcm c d cntB = b - b / c - b / d + b / lcm(c, d) cntB b - b / c - b / d + b / lcm(c, d) b - b / c - b / d b - b / c - b / d b b / c b c b / d b d b / lcm(c, d) b lcm(c, d) lcm c d long res = (cntB - cntA); res (cntB - cntA) cntB cntA if(a % c != 0 && a % d != 0) res++; a % c != 0 && a % d != 0 a % c != 0 a % c a c 0 a % d != 0 a % d a d 0 res++ res System.out.println(res) System.out.println System.out System System.out res String args[] args private static long gcd(long a, long b) {
    	if(b == 0)
    		return a;
    	return gcd(b, a % b);
    } gcd {
    	if(b == 0)
    		return a;
    	return gcd(b, a % b);
    } if(b == 0)
    		return a; b == 0 b 0 return a; a return gcd(b, a % b); gcd(b, a % b) gcd b a % b a b long a a long b b private static long lcm(long a, long b) {
    	return a / gcd(a, b) * b;
    } lcm {
    	return a / gcd(a, b) * b;
    } return a / gcd(a, b) * b; a / gcd(a, b) * b a / gcd(a, b) a gcd(a, b) gcd a b b long a a long b b public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long cntA = 0;
        long cntB = 0;
        long lcm = lcm(c, d);

  
        cntA = a - a / c - a / d + a / lcm(c, d);
        cntB = b - b / c - b / d + b / lcm(c, d);
 
        long res = (cntB - cntA);
        if(a % c != 0 && a % d != 0) res++;
        System.out.println(res);
    }

    private static long gcd(long a, long b) {
    	if(b == 0)
    		return a;
    	return gcd(b, a % b);
    }

    private static long lcm(long a, long b) {
    	return a / gcd(a, b) * b;
    }

} public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long cntA = 0;
        long cntB = 0;
        long lcm = lcm(c, d);

  
        cntA = a - a / c - a / d + a / lcm(c, d);
        cntB = b - b / c - b / d + b / lcm(c, d);
 
        long res = (cntB - cntA);
        if(a % c != 0 && a % d != 0) res++;
        System.out.println(res);
    }

    private static long gcd(long a, long b) {
    	if(b == 0)
    		return a;
    	return gcd(b, a % b);
    }

    private static long lcm(long a, long b) {
    	return a / gcd(a, b) * b;
    }

} Main
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        long cntA = 0;
        long cntB = 0;
        long lcm = lcm(c, d);

  
        cntA = a - a / c - a / d + a / lcm(c, d);
        cntB = b - b / c - b / d + b / lcm(c, d);
 
        long res = (cntB - cntA);
        if(a % c != 0 && a % d != 0) res++;
        System.out.println(res);
    }

    private static long gcd(long a, long b) {
    	if(b == 0)
    		return a;
    	return gcd(b, a % b);
    }

    private static long lcm(long a, long b) {
    	return a / gcd(a, b) * b;
    }

}


