import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long count =0 ;
    if( a == b)
    {
        if( (a%c)==0 && (a%d)==0 )
            System.out.println(0);
        else 
            System.out.println(1);
    }
    else
    {
        long a1 = a/c;
        long a11 = a%c;
        if( a11 != 0)
            a1++;
        long a2 = b/c;
        count = a2-a1+1;
        
        long b1=a/d;
        long b11 = a%d;
        if( b11 != 0)
            b1++;
        long b2 =b/d;
        count = count+(b2-b1+1);
        
        long gcdnum = gcd(c , d);
        long lcm = (c*d)/gcdnum;
        long c1 = a/lcm;
        if(a % lcm == 0)
            c1--;
        long c2 = b/lcm;
        count = count-(c2-c1);
        // System.out.println("a1="+a1+" a2="+a2+" b1="+b1+" b2="+b2+" c1="+c1+" c2="+c2);
        // System.out.println(count);
        System.out.println((b-a+1)-count);
    }
    
    
  }
  
    
    static long gcd(long a, long b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    }
      
} import java.util.*; util.* java public class Main
{
  public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long count =0 ;
    if( a == b)
    {
        if( (a%c)==0 && (a%d)==0 )
            System.out.println(0);
        else 
            System.out.println(1);
    }
    else
    {
        long a1 = a/c;
        long a11 = a%c;
        if( a11 != 0)
            a1++;
        long a2 = b/c;
        count = a2-a1+1;
        
        long b1=a/d;
        long b11 = a%d;
        if( b11 != 0)
            b1++;
        long b2 =b/d;
        count = count+(b2-b1+1);
        
        long gcdnum = gcd(c , d);
        long lcm = (c*d)/gcdnum;
        long c1 = a/lcm;
        if(a % lcm == 0)
            c1--;
        long c2 = b/lcm;
        count = count-(c2-c1);
        // System.out.println("a1="+a1+" a2="+a2+" b1="+b1+" b2="+b2+" c1="+c1+" c2="+c2);
        // System.out.println(count);
        System.out.println((b-a+1)-count);
    }
    
    
  }
  
    
    static long gcd(long a, long b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    }
      
} Main public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long count =0 ;
    if( a == b)
    {
        if( (a%c)==0 && (a%d)==0 )
            System.out.println(0);
        else 
            System.out.println(1);
    }
    else
    {
        long a1 = a/c;
        long a11 = a%c;
        if( a11 != 0)
            a1++;
        long a2 = b/c;
        count = a2-a1+1;
        
        long b1=a/d;
        long b11 = a%d;
        if( b11 != 0)
            b1++;
        long b2 =b/d;
        count = count+(b2-b1+1);
        
        long gcdnum = gcd(c , d);
        long lcm = (c*d)/gcdnum;
        long c1 = a/lcm;
        if(a % lcm == 0)
            c1--;
        long c2 = b/lcm;
        count = count-(c2-c1);
        // System.out.println("a1="+a1+" a2="+a2+" b1="+b1+" b2="+b2+" c1="+c1+" c2="+c2);
        // System.out.println(count);
        System.out.println((b-a+1)-count);
    }
    
    
  } main {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long count =0 ;
    if( a == b)
    {
        if( (a%c)==0 && (a%d)==0 )
            System.out.println(0);
        else 
            System.out.println(1);
    }
    else
    {
        long a1 = a/c;
        long a11 = a%c;
        if( a11 != 0)
            a1++;
        long a2 = b/c;
        count = a2-a1+1;
        
        long b1=a/d;
        long b11 = a%d;
        if( b11 != 0)
            b1++;
        long b2 =b/d;
        count = count+(b2-b1+1);
        
        long gcdnum = gcd(c , d);
        long lcm = (c*d)/gcdnum;
        long c1 = a/lcm;
        if(a % lcm == 0)
            c1--;
        long c2 = b/lcm;
        count = count-(c2-c1);
        // System.out.println("a1="+a1+" a2="+a2+" b1="+b1+" b2="+b2+" c1="+c1+" c2="+c2);
        // System.out.println(count);
        System.out.println((b-a+1)-count);
    }
    
    
  } 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.nextLong(); c sc.nextLong() sc.nextLong sc long d = sc.nextLong(); d sc.nextLong() sc.nextLong sc long count =0 ; count 0 if( a == b)
    {
        if( (a%c)==0 && (a%d)==0 )
            System.out.println(0);
        else 
            System.out.println(1);
    }
    else
    {
        long a1 = a/c;
        long a11 = a%c;
        if( a11 != 0)
            a1++;
        long a2 = b/c;
        count = a2-a1+1;
        
        long b1=a/d;
        long b11 = a%d;
        if( b11 != 0)
            b1++;
        long b2 =b/d;
        count = count+(b2-b1+1);
        
        long gcdnum = gcd(c , d);
        long lcm = (c*d)/gcdnum;
        long c1 = a/lcm;
        if(a % lcm == 0)
            c1--;
        long c2 = b/lcm;
        count = count-(c2-c1);
        // System.out.println("a1="+a1+" a2="+a2+" b1="+b1+" b2="+b2+" c1="+c1+" c2="+c2);
        // System.out.println(count);
        System.out.println((b-a+1)-count);
    } a == b a b {
        if( (a%c)==0 && (a%d)==0 )
            System.out.println(0);
        else 
            System.out.println(1);
    } if( (a%c)==0 && (a%d)==0 )
            System.out.println(0);
        else 
            System.out.println(1); (a%c)==0 && (a%d)==0 (a%c)==0 (a%c) a c 0 (a%d)==0 (a%d) a d 0 System.out.println(0) System.out.println System.out System System.out 0 System.out.println(1) System.out.println System.out System System.out 1 {
        long a1 = a/c;
        long a11 = a%c;
        if( a11 != 0)
            a1++;
        long a2 = b/c;
        count = a2-a1+1;
        
        long b1=a/d;
        long b11 = a%d;
        if( b11 != 0)
            b1++;
        long b2 =b/d;
        count = count+(b2-b1+1);
        
        long gcdnum = gcd(c , d);
        long lcm = (c*d)/gcdnum;
        long c1 = a/lcm;
        if(a % lcm == 0)
            c1--;
        long c2 = b/lcm;
        count = count-(c2-c1);
        // System.out.println("a1="+a1+" a2="+a2+" b1="+b1+" b2="+b2+" c1="+c1+" c2="+c2);
        // System.out.println(count);
        System.out.println((b-a+1)-count);
    } long a1 = a/c; a1 a/c a c long a11 = a%c; a11 a%c a c if( a11 != 0)
            a1++; a11 != 0 a11 0 a1++ a1 long a2 = b/c; a2 b/c b c count = a2-a1+1 count a2-a1+1 a2-a1 a2 a1 1 long b1=a/d; b1 a/d a d long b11 = a%d; b11 a%d a d if( b11 != 0)
            b1++; b11 != 0 b11 0 b1++ b1 long b2 =b/d; b2 b/d b d count = count+(b2-b1+1) count count+(b2-b1+1) count (b2-b1+1) b2-b1 b2 b1 1 long gcdnum = gcd(c , d); gcdnum gcd(c , d) gcd c d long lcm = (c*d)/gcdnum; lcm (c*d)/gcdnum (c*d) c d gcdnum long c1 = a/lcm; c1 a/lcm a lcm if(a % lcm == 0)
            c1--; a % lcm == 0 a % lcm a lcm 0 c1-- c1 long c2 = b/lcm; c2 b/lcm b lcm count = count-(c2-c1) count count-(c2-c1) count (c2-c1) c2 c1 System.out.println((b-a+1)-count) System.out.println System.out System System.out (b-a+1)-count (b-a+1) b-a b a 1 count String args[] args static long gcd(long a, long b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    } gcd { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    } if (b == 0) 
        return a; b == 0 b 0 return a; a return gcd(b, a % b); gcd(b, a % b) gcd b a % b a b long a a long b b public class Main
{
  public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long count =0 ;
    if( a == b)
    {
        if( (a%c)==0 && (a%d)==0 )
            System.out.println(0);
        else 
            System.out.println(1);
    }
    else
    {
        long a1 = a/c;
        long a11 = a%c;
        if( a11 != 0)
            a1++;
        long a2 = b/c;
        count = a2-a1+1;
        
        long b1=a/d;
        long b11 = a%d;
        if( b11 != 0)
            b1++;
        long b2 =b/d;
        count = count+(b2-b1+1);
        
        long gcdnum = gcd(c , d);
        long lcm = (c*d)/gcdnum;
        long c1 = a/lcm;
        if(a % lcm == 0)
            c1--;
        long c2 = b/lcm;
        count = count-(c2-c1);
        // System.out.println("a1="+a1+" a2="+a2+" b1="+b1+" b2="+b2+" c1="+c1+" c2="+c2);
        // System.out.println(count);
        System.out.println((b-a+1)-count);
    }
    
    
  }
  
    
    static long gcd(long a, long b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    }
      
} public class Main
{
  public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long count =0 ;
    if( a == b)
    {
        if( (a%c)==0 && (a%d)==0 )
            System.out.println(0);
        else 
            System.out.println(1);
    }
    else
    {
        long a1 = a/c;
        long a11 = a%c;
        if( a11 != 0)
            a1++;
        long a2 = b/c;
        count = a2-a1+1;
        
        long b1=a/d;
        long b11 = a%d;
        if( b11 != 0)
            b1++;
        long b2 =b/d;
        count = count+(b2-b1+1);
        
        long gcdnum = gcd(c , d);
        long lcm = (c*d)/gcdnum;
        long c1 = a/lcm;
        if(a % lcm == 0)
            c1--;
        long c2 = b/lcm;
        count = count-(c2-c1);
        // System.out.println("a1="+a1+" a2="+a2+" b1="+b1+" b2="+b2+" c1="+c1+" c2="+c2);
        // System.out.println(count);
        System.out.println((b-a+1)-count);
    }
    
    
  }
  
    
    static long gcd(long a, long b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    }
      
} Main
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long count =0 ;
    if( a == b)
    {
        if( (a%c)==0 && (a%d)==0 )
            System.out.println(0);
        else 
            System.out.println(1);
    }
    else
    {
        long a1 = a/c;
        long a11 = a%c;
        if( a11 != 0)
            a1++;
        long a2 = b/c;
        count = a2-a1+1;
        
        long b1=a/d;
        long b11 = a%d;
        if( b11 != 0)
            b1++;
        long b2 =b/d;
        count = count+(b2-b1+1);
        
        long gcdnum = gcd(c , d);
        long lcm = (c*d)/gcdnum;
        long c1 = a/lcm;
        if(a % lcm == 0)
            c1--;
        long c2 = b/lcm;
        count = count-(c2-c1);
        // System.out.println("a1="+a1+" a2="+a2+" b1="+b1+" b2="+b2+" c1="+c1+" c2="+c2);
        // System.out.println(count);
        System.out.println((b-a+1)-count);
    }
    
    
  }
  
    
    static long gcd(long a, long b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    }
      
}