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