import java.util.Scanner;

public class Main {

    static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}
    static long lcm (long a, long b) {return a*b/gcd(a,b);}

    
    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong()-1;
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        
        long cc = (B/C)-(A/C);
        long dc = (B/D)-(A/D);
        long lcm = lcm(C, D);
        
        long ccd = (B/lcm)-(A/lcm);
        System.out.println(B-A-cc-dc+ccd);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}
    static long lcm (long a, long b) {return a*b/gcd(a,b);}

    
    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong()-1;
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        
        long cc = (B/C)-(A/C);
        long dc = (B/D)-(A/D);
        long lcm = lcm(C, D);
        
        long ccd = (B/lcm)-(A/lcm);
        System.out.println(B-A-cc-dc+ccd);
    }
} Main static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;} gcd {return b>0?gcd(b,a%b):a;} return b>0?gcd(b,a%b):a; b>0?gcd(b,a%b):a b>0 b 0 gcd(b,a%b) gcd b a%b a b a long a a long b b static long lcm (long a, long b) {return a*b/gcd(a,b);} lcm {return a*b/gcd(a,b);} return a*b/gcd(a,b); a*b/gcd(a,b) a*b a b gcd(a,b) gcd a b long a a long b b public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong()-1;
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        
        long cc = (B/C)-(A/C);
        long dc = (B/D)-(A/D);
        long lcm = lcm(C, D);
        
        long ccd = (B/lcm)-(A/lcm);
        System.out.println(B-A-cc-dc+ccd);
    } main {

        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong()-1;
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        
        long cc = (B/C)-(A/C);
        long dc = (B/D)-(A/D);
        long lcm = lcm(C, D);
        
        long ccd = (B/lcm)-(A/lcm);
        System.out.println(B-A-cc-dc+ccd);
    } 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.nextLong(); C sc.nextLong() sc.nextLong sc long D = sc.nextLong(); D sc.nextLong() sc.nextLong sc long cc = (B/C)-(A/C); cc (B/C)-(A/C) (B/C) B C (A/C) A C long dc = (B/D)-(A/D); dc (B/D)-(A/D) (B/D) B D (A/D) A D long lcm = lcm(C, D); lcm lcm(C, D) lcm C D long ccd = (B/lcm)-(A/lcm); ccd (B/lcm)-(A/lcm) (B/lcm) B lcm (A/lcm) A lcm System.out.println(B-A-cc-dc+ccd) System.out.println System.out System System.out B-A-cc-dc+ccd B-A-cc-dc cc B-A-cc-dc B A cc dc ccd String args[] args public class Main {

    static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}
    static long lcm (long a, long b) {return a*b/gcd(a,b);}

    
    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong()-1;
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        
        long cc = (B/C)-(A/C);
        long dc = (B/D)-(A/D);
        long lcm = lcm(C, D);
        
        long ccd = (B/lcm)-(A/lcm);
        System.out.println(B-A-cc-dc+ccd);
    }
} public class Main {

    static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}
    static long lcm (long a, long b) {return a*b/gcd(a,b);}

    
    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong()-1;
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        
        long cc = (B/C)-(A/C);
        long dc = (B/D)-(A/D);
        long lcm = lcm(C, D);
        
        long ccd = (B/lcm)-(A/lcm);
        System.out.println(B-A-cc-dc+ccd);
    }
} Main
import java.util.Scanner;

public class Main {

    static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}
    static long lcm (long a, long b) {return a*b/gcd(a,b);}

    
    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong()-1;
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        
        long cc = (B/C)-(A/C);
        long dc = (B/D)-(A/D);
        long lcm = lcm(C, D);
        
        long ccd = (B/lcm)-(A/lcm);
        System.out.println(B-A-cc-dc+ccd);
    }
}