
import java.util.Scanner;

 class Main {

    public static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    public static long divisibleBy(long a, long b, long num){
        long from,to;
        if(a%num==0){
            from=a/num-1;
        }
        else
            from=a/num;

        to = b/num;
        return to-from;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a= in.nextLong();
        long b= in.nextLong();
        long c= in.nextLong();
        long d = in.nextLong();

        if(a>b){
            long temp=a;
            a=b;
            b=temp;
        }
        long lcm= (c*d)/gcd(c,d);
        long nums = b-a+1;
        long divisibleByC = divisibleBy(a,b,c);
        long divisibleByD = divisibleBy(a,b,d);
        long divisibleByLCM = divisibleBy(a,b,lcm);

        long ans= nums- (divisibleByC+divisibleByD-divisibleByLCM);
        System.out.println(ans);

    }
} import java.util.Scanner; Scanner java.util class Main {

    public static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    public static long divisibleBy(long a, long b, long num){
        long from,to;
        if(a%num==0){
            from=a/num-1;
        }
        else
            from=a/num;

        to = b/num;
        return to-from;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a= in.nextLong();
        long b= in.nextLong();
        long c= in.nextLong();
        long d = in.nextLong();

        if(a>b){
            long temp=a;
            a=b;
            b=temp;
        }
        long lcm= (c*d)/gcd(c,d);
        long nums = b-a+1;
        long divisibleByC = divisibleBy(a,b,c);
        long divisibleByD = divisibleBy(a,b,d);
        long divisibleByLCM = divisibleBy(a,b,lcm);

        long ans= nums- (divisibleByC+divisibleByD-divisibleByLCM);
        System.out.println(ans);

    }
} Main public static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    } gcd {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    } if (a == 0)
            return b; 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 public static long divisibleBy(long a, long b, long num){
        long from,to;
        if(a%num==0){
            from=a/num-1;
        }
        else
            from=a/num;

        to = b/num;
        return to-from;
    } divisibleBy {
        long from,to;
        if(a%num==0){
            from=a/num-1;
        }
        else
            from=a/num;

        to = b/num;
        return to-from;
    } long from from to; to if(a%num==0){
            from=a/num-1;
        }
        else
            from=a/num; a%num==0 a%num a num 0 {
            from=a/num-1;
        } from=a/num-1 from a/num-1 a/num a num 1 from=a/num from a/num a num to = b/num to b/num b num return to-from; to-from to from long a a long b b long num num public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a= in.nextLong();
        long b= in.nextLong();
        long c= in.nextLong();
        long d = in.nextLong();

        if(a>b){
            long temp=a;
            a=b;
            b=temp;
        }
        long lcm= (c*d)/gcd(c,d);
        long nums = b-a+1;
        long divisibleByC = divisibleBy(a,b,c);
        long divisibleByD = divisibleBy(a,b,d);
        long divisibleByLCM = divisibleBy(a,b,lcm);

        long ans= nums- (divisibleByC+divisibleByD-divisibleByLCM);
        System.out.println(ans);

    } main {
        Scanner in = new Scanner(System.in);
        long a= in.nextLong();
        long b= in.nextLong();
        long c= in.nextLong();
        long d = in.nextLong();

        if(a>b){
            long temp=a;
            a=b;
            b=temp;
        }
        long lcm= (c*d)/gcd(c,d);
        long nums = b-a+1;
        long divisibleByC = divisibleBy(a,b,c);
        long divisibleByD = divisibleBy(a,b,d);
        long divisibleByLCM = divisibleBy(a,b,lcm);

        long ans= nums- (divisibleByC+divisibleByD-divisibleByLCM);
        System.out.println(ans);

    } Scanner in = new Scanner(System.in); in new Scanner(System.in) long a= in.nextLong(); a in.nextLong() in.nextLong in long b= in.nextLong(); b in.nextLong() in.nextLong in long c= in.nextLong(); c in.nextLong() in.nextLong in long d = in.nextLong(); d in.nextLong() in.nextLong in if(a>b){
            long temp=a;
            a=b;
            b=temp;
        } a>b a b {
            long temp=a;
            a=b;
            b=temp;
        } long temp=a; temp a a=b a b b=temp b temp long lcm= (c*d)/gcd(c,d); lcm (c*d)/gcd(c,d) (c*d) c d gcd(c,d) gcd c d long nums = b-a+1; nums b-a+1 b-a b a 1 long divisibleByC = divisibleBy(a,b,c); divisibleByC divisibleBy(a,b,c) divisibleBy a b c long divisibleByD = divisibleBy(a,b,d); divisibleByD divisibleBy(a,b,d) divisibleBy a b d long divisibleByLCM = divisibleBy(a,b,lcm); divisibleByLCM divisibleBy(a,b,lcm) divisibleBy a b lcm long ans= nums- (divisibleByC+divisibleByD-divisibleByLCM); ans nums- (divisibleByC+divisibleByD-divisibleByLCM) nums (divisibleByC+divisibleByD-divisibleByLCM) divisibleByC+divisibleByD divisibleByC divisibleByD divisibleByLCM System.out.println(ans) System.out.println System.out System System.out ans String[] args args

import java.util.Scanner;

 class Main {

    public static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    public static long divisibleBy(long a, long b, long num){
        long from,to;
        if(a%num==0){
            from=a/num-1;
        }
        else
            from=a/num;

        to = b/num;
        return to-from;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long a= in.nextLong();
        long b= in.nextLong();
        long c= in.nextLong();
        long d = in.nextLong();

        if(a>b){
            long temp=a;
            a=b;
            b=temp;
        }
        long lcm= (c*d)/gcd(c,d);
        long nums = b-a+1;
        long divisibleByC = divisibleBy(a,b,c);
        long divisibleByD = divisibleBy(a,b,d);
        long divisibleByLCM = divisibleBy(a,b,lcm);

        long ans= nums- (divisibleByC+divisibleByD-divisibleByLCM);
        System.out.println(ans);

    }
}
