import java.io.*;
import java.util.*;

public class Main {
    PrintWriter out = new PrintWriter(System.out);
    long mod = 1000000000+7;
    public static void main(String[] args) throws Exception {
        Main main = new Main();
//        main.solve();
        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        // use i-indexed here
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        long lcm = c*d/gcd(c,d);
        long mc = MultipleInRange(a,b,c);
        long md = MultipleInRange(a,b,d);
        long repeat = MultipleInRange(a,b,lcm);
        return (b-a+1)-(mc+md-repeat);
    }
    long MultipleInRange(long lo, long hi, long x){
        return hi/x-(lo-1)/x;
    }
    long gcd(long x, long y){
        // first find gcd
        if(x<y){
            long c = x;
            x = y; y = c;
        }
        while(x%y!=0){
            long c = y;
            y = x%y;
            x = c;
        }
        return y;
    }
}
 import java.io.*; io.* java import java.util.*; util.* java public class Main {
    PrintWriter out = new PrintWriter(System.out);
    long mod = 1000000000+7;
    public static void main(String[] args) throws Exception {
        Main main = new Main();
//        main.solve();
        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        // use i-indexed here
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        long lcm = c*d/gcd(c,d);
        long mc = MultipleInRange(a,b,c);
        long md = MultipleInRange(a,b,d);
        long repeat = MultipleInRange(a,b,lcm);
        return (b-a+1)-(mc+md-repeat);
    }
    long MultipleInRange(long lo, long hi, long x){
        return hi/x-(lo-1)/x;
    }
    long gcd(long x, long y){
        // first find gcd
        if(x<y){
            long c = x;
            x = y; y = c;
        }
        while(x%y!=0){
            long c = y;
            y = x%y;
            x = c;
        }
        return y;
    }
} Main PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) long mod = 1000000000+7; mod 1000000000+7 1000000000 7 public static void main(String[] args) throws Exception {
        Main main = new Main();
//        main.solve();
        System.out.println(main.solve());
    } main {
        Main main = new Main();
//        main.solve();
        System.out.println(main.solve());
    } Main main = new Main(); main new Main() System.out.println(main.solve()) System.out.println System.out System System.out main.solve() main.solve main String[] args args long solve(){
        Scanner sc = new Scanner(System.in);
        // use i-indexed here
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        long lcm = c*d/gcd(c,d);
        long mc = MultipleInRange(a,b,c);
        long md = MultipleInRange(a,b,d);
        long repeat = MultipleInRange(a,b,lcm);
        return (b-a+1)-(mc+md-repeat);
    } solve {
        Scanner sc = new Scanner(System.in);
        // use i-indexed here
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        long lcm = c*d/gcd(c,d);
        long mc = MultipleInRange(a,b,c);
        long md = MultipleInRange(a,b,d);
        long repeat = MultipleInRange(a,b,lcm);
        return (b-a+1)-(mc+md-repeat);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = sc.nextLong() a sc.nextLong() sc.nextLong sc b = sc.nextLong() b sc.nextLong() sc.nextLong sc c = sc.nextLong() c sc.nextLong() sc.nextLong sc d = sc.nextLong(); d sc.nextLong() sc.nextLong sc long lcm = c*d/gcd(c,d); lcm c*d/gcd(c,d) c*d c d gcd(c,d) gcd c d long mc = MultipleInRange(a,b,c); mc MultipleInRange(a,b,c) MultipleInRange a b c long md = MultipleInRange(a,b,d); md MultipleInRange(a,b,d) MultipleInRange a b d long repeat = MultipleInRange(a,b,lcm); repeat MultipleInRange(a,b,lcm) MultipleInRange a b lcm return (b-a+1)-(mc+md-repeat); (b-a+1)-(mc+md-repeat) (b-a+1) b-a b a 1 (mc+md-repeat) mc+md mc md repeat long MultipleInRange(long lo, long hi, long x){
        return hi/x-(lo-1)/x;
    } MultipleInRange {
        return hi/x-(lo-1)/x;
    } return hi/x-(lo-1)/x; hi/x-(lo-1)/x hi/x hi x (lo-1)/x (lo-1) lo 1 x long lo lo long hi hi long x x long gcd(long x, long y){
        // first find gcd
        if(x<y){
            long c = x;
            x = y; y = c;
        }
        while(x%y!=0){
            long c = y;
            y = x%y;
            x = c;
        }
        return y;
    } gcd {
        // first find gcd
        if(x<y){
            long c = x;
            x = y; y = c;
        }
        while(x%y!=0){
            long c = y;
            y = x%y;
            x = c;
        }
        return y;
    } if(x<y){
            long c = x;
            x = y; y = c;
        } x<y x y {
            long c = x;
            x = y; y = c;
        } long c = x; c x x = y x y y = c y c while(x%y!=0){
            long c = y;
            y = x%y;
            x = c;
        } x%y!=0 x%y x y 0 {
            long c = y;
            y = x%y;
            x = c;
        } long c = y; c y y = x%y y x%y x y x = c x c return y; y long x x long y y public class Main {
    PrintWriter out = new PrintWriter(System.out);
    long mod = 1000000000+7;
    public static void main(String[] args) throws Exception {
        Main main = new Main();
//        main.solve();
        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        // use i-indexed here
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        long lcm = c*d/gcd(c,d);
        long mc = MultipleInRange(a,b,c);
        long md = MultipleInRange(a,b,d);
        long repeat = MultipleInRange(a,b,lcm);
        return (b-a+1)-(mc+md-repeat);
    }
    long MultipleInRange(long lo, long hi, long x){
        return hi/x-(lo-1)/x;
    }
    long gcd(long x, long y){
        // first find gcd
        if(x<y){
            long c = x;
            x = y; y = c;
        }
        while(x%y!=0){
            long c = y;
            y = x%y;
            x = c;
        }
        return y;
    }
} public class Main {
    PrintWriter out = new PrintWriter(System.out);
    long mod = 1000000000+7;
    public static void main(String[] args) throws Exception {
        Main main = new Main();
//        main.solve();
        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        // use i-indexed here
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        long lcm = c*d/gcd(c,d);
        long mc = MultipleInRange(a,b,c);
        long md = MultipleInRange(a,b,d);
        long repeat = MultipleInRange(a,b,lcm);
        return (b-a+1)-(mc+md-repeat);
    }
    long MultipleInRange(long lo, long hi, long x){
        return hi/x-(lo-1)/x;
    }
    long gcd(long x, long y){
        // first find gcd
        if(x<y){
            long c = x;
            x = y; y = c;
        }
        while(x%y!=0){
            long c = y;
            y = x%y;
            x = c;
        }
        return y;
    }
} Main
import java.io.*;
import java.util.*;

public class Main {
    PrintWriter out = new PrintWriter(System.out);
    long mod = 1000000000+7;
    public static void main(String[] args) throws Exception {
        Main main = new Main();
//        main.solve();
        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        // use i-indexed here
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        long lcm = c*d/gcd(c,d);
        long mc = MultipleInRange(a,b,c);
        long md = MultipleInRange(a,b,d);
        long repeat = MultipleInRange(a,b,lcm);
        return (b-a+1)-(mc+md-repeat);
    }
    long MultipleInRange(long lo, long hi, long x){
        return hi/x-(lo-1)/x;
    }
    long gcd(long x, long y){
        // first find gcd
        if(x<y){
            long c = x;
            x = y; y = c;
        }
        while(x%y!=0){
            long c = y;
            y = x%y;
            x = c;
        }
        return y;
    }
}

