import java.util.*;

public class Main
{
    public static long y(long m, long n)
    {
        long tmp;
        while(m%n != 0)
        {
            tmp = n;
            n = m%n;
            m = tmp;
        }
        return n;
    }
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        long a, b, c, d;
        a = sc.nextLong();
        b = sc.nextLong();
        c = sc.nextLong();
        d = sc.nextLong();
        long count = b - a + (long)1;

        long gcd = y(c,d);
        long lcd = c*d/gcd;
        

        // if(a%c==0 && a%d==0)
        // {
        //     count++;
        // }
        // if(b%c==0 && b%d==0){
        //     count++;
        // }
        long tmp;
        tmp = b/c + b/d - b/lcd - (a-1)/c - (a-1)/d + (a-1)/lcd;
        
            
        count = count - tmp;

        System.out.println(count);
        
        
    }
}
 import java.util.*; util.* java public class Main
{
    public static long y(long m, long n)
    {
        long tmp;
        while(m%n != 0)
        {
            tmp = n;
            n = m%n;
            m = tmp;
        }
        return n;
    }
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        long a, b, c, d;
        a = sc.nextLong();
        b = sc.nextLong();
        c = sc.nextLong();
        d = sc.nextLong();
        long count = b - a + (long)1;

        long gcd = y(c,d);
        long lcd = c*d/gcd;
        

        // if(a%c==0 && a%d==0)
        // {
        //     count++;
        // }
        // if(b%c==0 && b%d==0){
        //     count++;
        // }
        long tmp;
        tmp = b/c + b/d - b/lcd - (a-1)/c - (a-1)/d + (a-1)/lcd;
        
            
        count = count - tmp;

        System.out.println(count);
        
        
    }
} Main public static long y(long m, long n)
    {
        long tmp;
        while(m%n != 0)
        {
            tmp = n;
            n = m%n;
            m = tmp;
        }
        return n;
    } y {
        long tmp;
        while(m%n != 0)
        {
            tmp = n;
            n = m%n;
            m = tmp;
        }
        return n;
    } long tmp; tmp while(m%n != 0)
        {
            tmp = n;
            n = m%n;
            m = tmp;
        } m%n != 0 m%n m n 0 {
            tmp = n;
            n = m%n;
            m = tmp;
        } tmp = n tmp n n = m%n n m%n m n m = tmp m tmp return n; n long m m long n n public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        long a, b, c, d;
        a = sc.nextLong();
        b = sc.nextLong();
        c = sc.nextLong();
        d = sc.nextLong();
        long count = b - a + (long)1;

        long gcd = y(c,d);
        long lcd = c*d/gcd;
        

        // if(a%c==0 && a%d==0)
        // {
        //     count++;
        // }
        // if(b%c==0 && b%d==0){
        //     count++;
        // }
        long tmp;
        tmp = b/c + b/d - b/lcd - (a-1)/c - (a-1)/d + (a-1)/lcd;
        
            
        count = count - tmp;

        System.out.println(count);
        
        
    } main {
        Scanner sc = new Scanner(System.in);
        long a, b, c, d;
        a = sc.nextLong();
        b = sc.nextLong();
        c = sc.nextLong();
        d = sc.nextLong();
        long count = b - a + (long)1;

        long gcd = y(c,d);
        long lcd = c*d/gcd;
        

        // if(a%c==0 && a%d==0)
        // {
        //     count++;
        // }
        // if(b%c==0 && b%d==0){
        //     count++;
        // }
        long tmp;
        tmp = b/c + b/d - b/lcd - (a-1)/c - (a-1)/d + (a-1)/lcd;
        
            
        count = count - tmp;

        System.out.println(count);
        
        
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a a b b c c d; d a = sc.nextLong() a sc.nextLong() sc.nextLong sc b = sc.nextLong() b sc.nextLong() sc.nextLong sc c = sc.nextLong() c sc.nextLong() sc.nextLong sc d = sc.nextLong() d sc.nextLong() sc.nextLong sc long count = b - a + (long)1; count b - a + (long)1 b - a b a (long)1 long gcd = y(c,d); gcd y(c,d) y c d long lcd = c*d/gcd; lcd c*d/gcd c*d c d gcd long tmp; tmp tmp = b/c + b/d - b/lcd - (a-1)/c - (a-1)/d + (a-1)/lcd tmp b/c + b/d - b/lcd - (a-1)/c - (a-1)/d + (a-1)/lcd b/c + b/d - b/lcd - (a-1)/c - (a-1)/d (a-1)/c b/c + b/d - b/lcd - (a-1)/c - (a-1)/d b/c + b/d b/c b c b/d b d b/lcd b lcd (a-1)/c (a-1) a 1 c (a-1)/d (a-1) a 1 d (a-1)/lcd (a-1) a 1 lcd count = count - tmp count count - tmp count tmp System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main
{
    public static long y(long m, long n)
    {
        long tmp;
        while(m%n != 0)
        {
            tmp = n;
            n = m%n;
            m = tmp;
        }
        return n;
    }
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        long a, b, c, d;
        a = sc.nextLong();
        b = sc.nextLong();
        c = sc.nextLong();
        d = sc.nextLong();
        long count = b - a + (long)1;

        long gcd = y(c,d);
        long lcd = c*d/gcd;
        

        // if(a%c==0 && a%d==0)
        // {
        //     count++;
        // }
        // if(b%c==0 && b%d==0){
        //     count++;
        // }
        long tmp;
        tmp = b/c + b/d - b/lcd - (a-1)/c - (a-1)/d + (a-1)/lcd;
        
            
        count = count - tmp;

        System.out.println(count);
        
        
    }
} public class Main
{
    public static long y(long m, long n)
    {
        long tmp;
        while(m%n != 0)
        {
            tmp = n;
            n = m%n;
            m = tmp;
        }
        return n;
    }
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        long a, b, c, d;
        a = sc.nextLong();
        b = sc.nextLong();
        c = sc.nextLong();
        d = sc.nextLong();
        long count = b - a + (long)1;

        long gcd = y(c,d);
        long lcd = c*d/gcd;
        

        // if(a%c==0 && a%d==0)
        // {
        //     count++;
        // }
        // if(b%c==0 && b%d==0){
        //     count++;
        // }
        long tmp;
        tmp = b/c + b/d - b/lcd - (a-1)/c - (a-1)/d + (a-1)/lcd;
        
            
        count = count - tmp;

        System.out.println(count);
        
        
    }
} Main
import java.util.*;

public class Main
{
    public static long y(long m, long n)
    {
        long tmp;
        while(m%n != 0)
        {
            tmp = n;
            n = m%n;
            m = tmp;
        }
        return n;
    }
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        long a, b, c, d;
        a = sc.nextLong();
        b = sc.nextLong();
        c = sc.nextLong();
        d = sc.nextLong();
        long count = b - a + (long)1;

        long gcd = y(c,d);
        long lcd = c*d/gcd;
        

        // if(a%c==0 && a%d==0)
        // {
        //     count++;
        // }
        // if(b%c==0 && b%d==0){
        //     count++;
        // }
        long tmp;
        tmp = b/c + b/d - b/lcd - (a-1)/c - (a-1)/d + (a-1)/lcd;
        
            
        count = count - tmp;

        System.out.println(count);
        
        
    }
}

