/*https://atcoder.jp/contests/abc131/tasks/abc131_c*/

import java.util.*;
import java.awt.*;

class Main{
 
    private static Scanner sc = new Scanner(System.in);
    

    public static long gcd(long a,long b){
        if(b==0){
            return a;
        }else{
            return gcd(b,a%b);
        }
    }
    public static long lcm(long a,long b){
        return a/gcd(a,b)*b;
    }
    public static long divi(long l,long a,long b){
        long res = l;
        res -= l/a;
        res -= l/b;
        res += l/lcm(a,b);
        return res;
    }
    public static void main(String[] args) {
        String s = sc.next();
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();

        long a = Long.parseLong(s); 
        long b = Long.parseLong(s1);
        long c = Long.parseLong(s2);
        long d = Long.parseLong(s3);
        //char[] code = s.toCharArray();
        long ans = divi(b,c,d)-divi(a-1,c,d);
        
        System.out.println(ans); }
} import java.util.*; util.* java import java.awt.*; awt.* java class Main{
 
    private static Scanner sc = new Scanner(System.in);
    

    public static long gcd(long a,long b){
        if(b==0){
            return a;
        }else{
            return gcd(b,a%b);
        }
    }
    public static long lcm(long a,long b){
        return a/gcd(a,b)*b;
    }
    public static long divi(long l,long a,long b){
        long res = l;
        res -= l/a;
        res -= l/b;
        res += l/lcm(a,b);
        return res;
    }
    public static void main(String[] args) {
        String s = sc.next();
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();

        long a = Long.parseLong(s); 
        long b = Long.parseLong(s1);
        long c = Long.parseLong(s2);
        long d = Long.parseLong(s3);
        //char[] code = s.toCharArray();
        long ans = divi(b,c,d)-divi(a-1,c,d);
        
        System.out.println(ans); }
} Main private static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static long gcd(long a,long b){
        if(b==0){
            return a;
        }else{
            return gcd(b,a%b);
        }
    } gcd {
        if(b==0){
            return a;
        }else{
            return gcd(b,a%b);
        }
    } if(b==0){
            return a;
        }else{
            return gcd(b,a%b);
        } b==0 b 0 {
            return a;
        } return a; a {
            return gcd(b,a%b);
        } return gcd(b,a%b); gcd(b,a%b) gcd b a%b a b long a a long b b public 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 static long divi(long l,long a,long b){
        long res = l;
        res -= l/a;
        res -= l/b;
        res += l/lcm(a,b);
        return res;
    } divi {
        long res = l;
        res -= l/a;
        res -= l/b;
        res += l/lcm(a,b);
        return res;
    } long res = l; res l res -= l/a res l/a l a res -= l/b res l/b l b res += l/lcm(a,b) res l/lcm(a,b) l lcm(a,b) lcm a b return res; res long l l long a a long b b public static void main(String[] args) {
        String s = sc.next();
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();

        long a = Long.parseLong(s); 
        long b = Long.parseLong(s1);
        long c = Long.parseLong(s2);
        long d = Long.parseLong(s3);
        //char[] code = s.toCharArray();
        long ans = divi(b,c,d)-divi(a-1,c,d);
        
        System.out.println(ans); } main {
        String s = sc.next();
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();

        long a = Long.parseLong(s); 
        long b = Long.parseLong(s1);
        long c = Long.parseLong(s2);
        long d = Long.parseLong(s3);
        //char[] code = s.toCharArray();
        long ans = divi(b,c,d)-divi(a-1,c,d);
        
        System.out.println(ans); } String s = sc.next(); s sc.next() sc.next sc String s1 = sc.next(); s1 sc.next() sc.next sc String s2 = sc.next(); s2 sc.next() sc.next sc String s3 = sc.next(); s3 sc.next() sc.next sc long a = Long.parseLong(s); a Long.parseLong(s) Long.parseLong Long s long b = Long.parseLong(s1); b Long.parseLong(s1) Long.parseLong Long s1 long c = Long.parseLong(s2); c Long.parseLong(s2) Long.parseLong Long s2 long d = Long.parseLong(s3); d Long.parseLong(s3) Long.parseLong Long s3 long ans = divi(b,c,d)-divi(a-1,c,d); ans divi(b,c,d)-divi(a-1,c,d) divi(b,c,d) divi b c d divi(a-1,c,d) divi a-1 a 1 c d System.out.println(ans) System.out.println System.out System System.out ans String[] args args
/*https://atcoder.jp/contests/abc131/tasks/abc131_c*/

import java.util.*;
import java.awt.*;

class Main{
 
    private static Scanner sc = new Scanner(System.in);
    

    public static long gcd(long a,long b){
        if(b==0){
            return a;
        }else{
            return gcd(b,a%b);
        }
    }
    public static long lcm(long a,long b){
        return a/gcd(a,b)*b;
    }
    public static long divi(long l,long a,long b){
        long res = l;
        res -= l/a;
        res -= l/b;
        res += l/lcm(a,b);
        return res;
    }
    public static void main(String[] args) {
        String s = sc.next();
        String s1 = sc.next();
        String s2 = sc.next();
        String s3 = sc.next();

        long a = Long.parseLong(s); 
        long b = Long.parseLong(s1);
        long c = Long.parseLong(s2);
        long d = Long.parseLong(s3);
        //char[] code = s.toCharArray();
        long ans = divi(b,c,d)-divi(a-1,c,d);
        
        System.out.println(ans); }
}
