import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.List;

public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        long c=sc.nextInt();
        long d=sc.nextInt();
        long x=b-a+1 - ((b/c) - (a/c) + (b/d) - (a/d) - ((b/(lcm(c,d))) - (a/(lcm(c,d)))));
//        System.out.println(x);
        if (a%c==0)x--;
        if (a%d==0)x--;
        if (a%(lcm(c,d))==0)x++;
        System.out.println(x);

    }
    static long gcd(long a,long b){
        if(a==0)return b;
        else return gcd(b%a,a);
    }
    static long lcm(long a,long b){
        return (a*b)/gcd(a,b);
    }

}
 import java.awt.*; awt.* java import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.*; util.* java import java.util.List; List java.util public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        long c=sc.nextInt();
        long d=sc.nextInt();
        long x=b-a+1 - ((b/c) - (a/c) + (b/d) - (a/d) - ((b/(lcm(c,d))) - (a/(lcm(c,d)))));
//        System.out.println(x);
        if (a%c==0)x--;
        if (a%d==0)x--;
        if (a%(lcm(c,d))==0)x++;
        System.out.println(x);

    }
    static long gcd(long a,long b){
        if(a==0)return b;
        else return gcd(b%a,a);
    }
    static long lcm(long a,long b){
        return (a*b)/gcd(a,b);
    }

} Main public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        long c=sc.nextInt();
        long d=sc.nextInt();
        long x=b-a+1 - ((b/c) - (a/c) + (b/d) - (a/d) - ((b/(lcm(c,d))) - (a/(lcm(c,d)))));
//        System.out.println(x);
        if (a%c==0)x--;
        if (a%d==0)x--;
        if (a%(lcm(c,d))==0)x++;
        System.out.println(x);

    } main {
        Scanner sc = new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        long c=sc.nextInt();
        long d=sc.nextInt();
        long x=b-a+1 - ((b/c) - (a/c) + (b/d) - (a/d) - ((b/(lcm(c,d))) - (a/(lcm(c,d)))));
//        System.out.println(x);
        if (a%c==0)x--;
        if (a%d==0)x--;
        if (a%(lcm(c,d))==0)x++;
        System.out.println(x);

    } 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.nextInt(); c sc.nextInt() sc.nextInt sc long d=sc.nextInt(); d sc.nextInt() sc.nextInt sc long x=b-a+1 - ((b/c) - (a/c) + (b/d) - (a/d) - ((b/(lcm(c,d))) - (a/(lcm(c,d))))); x b-a+1 - ((b/c) - (a/c) + (b/d) - (a/d) - ((b/(lcm(c,d))) - (a/(lcm(c,d))))) b-a+1 b-a b a 1 ((b/c) - (a/c) + (b/d) - (a/d) - ((b/(lcm(c,d))) - (a/(lcm(c,d))))) (b/c) - (a/c) + (b/d) - (a/d) - ((b/(lcm(c,d))) - (a/(lcm(c,d)))) (b/c) - (a/c) + (b/d) (b/c) - (a/c) (b/c) b c (a/c) a c (b/d) b d (a/d) a d ((b/(lcm(c,d))) - (a/(lcm(c,d)))) (b/(lcm(c,d))) b (lcm(c,d)) lcm c d (a/(lcm(c,d))) a (lcm(c,d)) lcm c d if (a%c==0)x--; a%c==0 a%c a c 0 x-- x if (a%d==0)x--; a%d==0 a%d a d 0 x-- x if (a%(lcm(c,d))==0)x++; a%(lcm(c,d))==0 a%(lcm(c,d)) a (lcm(c,d)) lcm c d 0 x++ x System.out.println(x) System.out.println System.out System System.out x String args[] args static long gcd(long a,long b){
        if(a==0)return b;
        else return gcd(b%a,a);
    } gcd {
        if(a==0)return b;
        else return gcd(b%a,a);
    } if(a==0)return b;
        else return gcd(b%a,a); a==0 a 0 return b; b return gcd(b%a,a); gcd(b%a,a) gcd b%a b a 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 class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        long c=sc.nextInt();
        long d=sc.nextInt();
        long x=b-a+1 - ((b/c) - (a/c) + (b/d) - (a/d) - ((b/(lcm(c,d))) - (a/(lcm(c,d)))));
//        System.out.println(x);
        if (a%c==0)x--;
        if (a%d==0)x--;
        if (a%(lcm(c,d))==0)x++;
        System.out.println(x);

    }
    static long gcd(long a,long b){
        if(a==0)return b;
        else return gcd(b%a,a);
    }
    static long lcm(long a,long b){
        return (a*b)/gcd(a,b);
    }

} public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        long c=sc.nextInt();
        long d=sc.nextInt();
        long x=b-a+1 - ((b/c) - (a/c) + (b/d) - (a/d) - ((b/(lcm(c,d))) - (a/(lcm(c,d)))));
//        System.out.println(x);
        if (a%c==0)x--;
        if (a%d==0)x--;
        if (a%(lcm(c,d))==0)x++;
        System.out.println(x);

    }
    static long gcd(long a,long b){
        if(a==0)return b;
        else return gcd(b%a,a);
    }
    static long lcm(long a,long b){
        return (a*b)/gcd(a,b);
    }

} Main
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.List;

public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        long c=sc.nextInt();
        long d=sc.nextInt();
        long x=b-a+1 - ((b/c) - (a/c) + (b/d) - (a/d) - ((b/(lcm(c,d))) - (a/(lcm(c,d)))));
//        System.out.println(x);
        if (a%c==0)x--;
        if (a%d==0)x--;
        if (a%(lcm(c,d))==0)x++;
        System.out.println(x);

    }
    static long gcd(long a,long b){
        if(a==0)return b;
        else return gcd(b%a,a);
    }
    static long lcm(long a,long b){
        return (a*b)/gcd(a,b);
    }

}

