import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong() - 1;
    long b = sc.nextLong();
    long c = sc.nextInt();
    long d = sc.nextInt();
    long final_a = 0;
    long final_b = 0;
    long ac = 0;
    long ad = 0;
    long bc = 0;
    long bd = 0;
    long acd = 0; 
    long bcd = 0;

    long cd = lcm(c, d);

    ac = a / c;
    ad = a / d;
    bc = b / c;
    bd = b / d;
    acd = a / cd;
    bcd = b / cd;

    final_a = a - ac - ad + acd;
    final_b = b - bc - bd + bcd;

    System.out.println(final_b - final_a);



    

    
    
    }
    
    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.io.BufferedReader; BufferedReader java.io import java.io.*; io.* java import java.util.*; util.* java import java.util.ArrayList; ArrayList java.util import java.util.Iterator; Iterator java.util import java.util.List; List java.util import java.util.Collections; Collections java.util import java.util.Arrays; Arrays java.util public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong() - 1;
    long b = sc.nextLong();
    long c = sc.nextInt();
    long d = sc.nextInt();
    long final_a = 0;
    long final_b = 0;
    long ac = 0;
    long ad = 0;
    long bc = 0;
    long bd = 0;
    long acd = 0; 
    long bcd = 0;

    long cd = lcm(c, d);

    ac = a / c;
    ad = a / d;
    bc = b / c;
    bd = b / d;
    acd = a / cd;
    bcd = b / cd;

    final_a = a - ac - ad + acd;
    final_b = b - bc - bd + bcd;

    System.out.println(final_b - final_a);



    

    
    
    }
    
    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(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong() - 1;
    long b = sc.nextLong();
    long c = sc.nextInt();
    long d = sc.nextInt();
    long final_a = 0;
    long final_b = 0;
    long ac = 0;
    long ad = 0;
    long bc = 0;
    long bd = 0;
    long acd = 0; 
    long bcd = 0;

    long cd = lcm(c, d);

    ac = a / c;
    ad = a / d;
    bc = b / c;
    bd = b / d;
    acd = a / cd;
    bcd = b / cd;

    final_a = a - ac - ad + acd;
    final_b = b - bc - bd + bcd;

    System.out.println(final_b - final_a);



    

    
    
    } main {
    
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong() - 1;
    long b = sc.nextLong();
    long c = sc.nextInt();
    long d = sc.nextInt();
    long final_a = 0;
    long final_b = 0;
    long ac = 0;
    long ad = 0;
    long bc = 0;
    long bd = 0;
    long acd = 0; 
    long bcd = 0;

    long cd = lcm(c, d);

    ac = a / c;
    ad = a / d;
    bc = b / c;
    bd = b / d;
    acd = a / cd;
    bcd = b / cd;

    final_a = a - ac - ad + acd;
    final_b = b - bc - bd + bcd;

    System.out.println(final_b - final_a);



    

    
    
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = sc.nextLong() - 1; a sc.nextLong() - 1 sc.nextLong() sc.nextLong sc 1 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 final_a = 0; final_a 0 long final_b = 0; final_b 0 long ac = 0; ac 0 long ad = 0; ad 0 long bc = 0; bc 0 long bd = 0; bd 0 long acd = 0; acd 0 long bcd = 0; bcd 0 long cd = lcm(c, d); cd lcm(c, d) lcm c d ac = a / c ac a / c a c ad = a / d ad a / d a d bc = b / c bc b / c b c bd = b / d bd b / d b d acd = a / cd acd a / cd a cd bcd = b / cd bcd b / cd b cd final_a = a - ac - ad + acd final_a a - ac - ad + acd a - ac - ad a - ac - ad a ac ad acd final_b = b - bc - bd + bcd final_b b - bc - bd + bcd b - bc - bd b - bc - bd b bc bd bcd System.out.println(final_b - final_a) System.out.println System.out System System.out final_b - final_a final_b final_a final 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(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong() - 1;
    long b = sc.nextLong();
    long c = sc.nextInt();
    long d = sc.nextInt();
    long final_a = 0;
    long final_b = 0;
    long ac = 0;
    long ad = 0;
    long bc = 0;
    long bd = 0;
    long acd = 0; 
    long bcd = 0;

    long cd = lcm(c, d);

    ac = a / c;
    ad = a / d;
    bc = b / c;
    bd = b / d;
    acd = a / cd;
    bcd = b / cd;

    final_a = a - ac - ad + acd;
    final_b = b - bc - bd + bcd;

    System.out.println(final_b - final_a);



    

    
    
    }
    
    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(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong() - 1;
    long b = sc.nextLong();
    long c = sc.nextInt();
    long d = sc.nextInt();
    long final_a = 0;
    long final_b = 0;
    long ac = 0;
    long ad = 0;
    long bc = 0;
    long bd = 0;
    long acd = 0; 
    long bcd = 0;

    long cd = lcm(c, d);

    ac = a / c;
    ad = a / d;
    bc = b / c;
    bd = b / d;
    acd = a / cd;
    bcd = b / cd;

    final_a = a - ac - ad + acd;
    final_b = b - bc - bd + bcd;

    System.out.println(final_b - final_a);



    

    
    
    }
    
    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.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong() - 1;
    long b = sc.nextLong();
    long c = sc.nextInt();
    long d = sc.nextInt();
    long final_a = 0;
    long final_b = 0;
    long ac = 0;
    long ad = 0;
    long bc = 0;
    long bd = 0;
    long acd = 0; 
    long bcd = 0;

    long cd = lcm(c, d);

    ac = a / c;
    ad = a / d;
    bc = b / c;
    bd = b / d;
    acd = a / cd;
    bcd = b / cd;

    final_a = a - ac - ad + acd;
    final_b = b - bc - bd + bcd;

    System.out.println(final_b - final_a);



    

    
    
    }
    
    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);
    }
}