import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        long a=Long.parseLong(sc.next());
        long b=Long.parseLong(sc.next());
        long c=Long.parseLong(sc.next());
        long d=Long.parseLong(sc.next());
        long cd=lcm(c,d);
        long ans=0,x,y;
        x=(a+c-1)/c;
        y=b/c;
        ans+=y-x+1;
        
        x=(a+d-1)/d;
        y=b/d;
        ans+=y-x+1;
        
        x=(a+cd-1)/cd;
        y=b/cd;
        ans-=y-x+1;
        System.out.println(b-a+1-ans);
    }
    public static long gcd(long a,long b){
        if(a<b){
        a^=b^=a;
        b^=a;}
        if(b!=0)
        return gcd(a%b,b);
        else return a;
    }public static long lcm(long a,long b){
        return a*b/gcd(a,b);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        long a=Long.parseLong(sc.next());
        long b=Long.parseLong(sc.next());
        long c=Long.parseLong(sc.next());
        long d=Long.parseLong(sc.next());
        long cd=lcm(c,d);
        long ans=0,x,y;
        x=(a+c-1)/c;
        y=b/c;
        ans+=y-x+1;
        
        x=(a+d-1)/d;
        y=b/d;
        ans+=y-x+1;
        
        x=(a+cd-1)/cd;
        y=b/cd;
        ans-=y-x+1;
        System.out.println(b-a+1-ans);
    }
    public static long gcd(long a,long b){
        if(a<b){
        a^=b^=a;
        b^=a;}
        if(b!=0)
        return gcd(a%b,b);
        else return a;
    }public static long lcm(long a,long b){
        return a*b/gcd(a,b);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        long a=Long.parseLong(sc.next());
        long b=Long.parseLong(sc.next());
        long c=Long.parseLong(sc.next());
        long d=Long.parseLong(sc.next());
        long cd=lcm(c,d);
        long ans=0,x,y;
        x=(a+c-1)/c;
        y=b/c;
        ans+=y-x+1;
        
        x=(a+d-1)/d;
        y=b/d;
        ans+=y-x+1;
        
        x=(a+cd-1)/cd;
        y=b/cd;
        ans-=y-x+1;
        System.out.println(b-a+1-ans);
    } main {
        Scanner sc=new Scanner(System.in);
        long a=Long.parseLong(sc.next());
        long b=Long.parseLong(sc.next());
        long c=Long.parseLong(sc.next());
        long d=Long.parseLong(sc.next());
        long cd=lcm(c,d);
        long ans=0,x,y;
        x=(a+c-1)/c;
        y=b/c;
        ans+=y-x+1;
        
        x=(a+d-1)/d;
        y=b/d;
        ans+=y-x+1;
        
        x=(a+cd-1)/cd;
        y=b/cd;
        ans-=y-x+1;
        System.out.println(b-a+1-ans);
    } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) long a=Long.parseLong(sc.next()); a Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long b=Long.parseLong(sc.next()); b Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long c=Long.parseLong(sc.next()); c Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long d=Long.parseLong(sc.next()); d Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long cd=lcm(c,d); cd lcm(c,d) lcm c d long ans=0 ans 0 x x y; y x=(a+c-1)/c x (a+c-1)/c (a+c-1) a+c a c 1 c y=b/c y b/c b c ans+=y-x+1 ans y-x+1 y-x y x 1 x=(a+d-1)/d x (a+d-1)/d (a+d-1) a+d a d 1 d y=b/d y b/d b d ans+=y-x+1 ans y-x+1 y-x y x 1 x=(a+cd-1)/cd x (a+cd-1)/cd (a+cd-1) a+cd a cd 1 cd y=b/cd y b/cd b cd ans-=y-x+1 ans y-x+1 y-x y x 1 System.out.println(b-a+1-ans) System.out.println System.out System System.out b-a+1-ans b-a+1 b-a b a 1 ans String[] args args public static long gcd(long a,long b){
        if(a<b){
        a^=b^=a;
        b^=a;}
        if(b!=0)
        return gcd(a%b,b);
        else return a;
    } gcd {
        if(a<b){
        a^=b^=a;
        b^=a;}
        if(b!=0)
        return gcd(a%b,b);
        else return a;
    } if(a<b){
        a^=b^=a;
        b^=a;} a<b a b {
        a^=b^=a;
        b^=a;} a^=b^=a a b^=a b a b^=a b a if(b!=0)
        return gcd(a%b,b);
        else return a; b!=0 b 0 return gcd(a%b,b); gcd(a%b,b) gcd a%b a b b return a; a long a a long b b public 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 Exception {
        Scanner sc=new Scanner(System.in);
        long a=Long.parseLong(sc.next());
        long b=Long.parseLong(sc.next());
        long c=Long.parseLong(sc.next());
        long d=Long.parseLong(sc.next());
        long cd=lcm(c,d);
        long ans=0,x,y;
        x=(a+c-1)/c;
        y=b/c;
        ans+=y-x+1;
        
        x=(a+d-1)/d;
        y=b/d;
        ans+=y-x+1;
        
        x=(a+cd-1)/cd;
        y=b/cd;
        ans-=y-x+1;
        System.out.println(b-a+1-ans);
    }
    public static long gcd(long a,long b){
        if(a<b){
        a^=b^=a;
        b^=a;}
        if(b!=0)
        return gcd(a%b,b);
        else return a;
    }public static long lcm(long a,long b){
        return a*b/gcd(a,b);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        long a=Long.parseLong(sc.next());
        long b=Long.parseLong(sc.next());
        long c=Long.parseLong(sc.next());
        long d=Long.parseLong(sc.next());
        long cd=lcm(c,d);
        long ans=0,x,y;
        x=(a+c-1)/c;
        y=b/c;
        ans+=y-x+1;
        
        x=(a+d-1)/d;
        y=b/d;
        ans+=y-x+1;
        
        x=(a+cd-1)/cd;
        y=b/cd;
        ans-=y-x+1;
        System.out.println(b-a+1-ans);
    }
    public static long gcd(long a,long b){
        if(a<b){
        a^=b^=a;
        b^=a;}
        if(b!=0)
        return gcd(a%b,b);
        else return a;
    }public static long lcm(long a,long b){
        return a*b/gcd(a,b);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        long a=Long.parseLong(sc.next());
        long b=Long.parseLong(sc.next());
        long c=Long.parseLong(sc.next());
        long d=Long.parseLong(sc.next());
        long cd=lcm(c,d);
        long ans=0,x,y;
        x=(a+c-1)/c;
        y=b/c;
        ans+=y-x+1;
        
        x=(a+d-1)/d;
        y=b/d;
        ans+=y-x+1;
        
        x=(a+cd-1)/cd;
        y=b/cd;
        ans-=y-x+1;
        System.out.println(b-a+1-ans);
    }
    public static long gcd(long a,long b){
        if(a<b){
        a^=b^=a;
        b^=a;}
        if(b!=0)
        return gcd(a%b,b);
        else return a;
    }public static long lcm(long a,long b){
        return a*b/gcd(a,b);
    }
}
