import java.util.Scanner;
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 dc=d*c/gcd((int)d,(int)c);
		
		long x1=b/c;
		long x2=b/d;
		long x3=b/dc;
		
		long ans1=x1+x2-x3;
		//System.out.println(ans1);
		
		long t1=(a-1)/c;
		long t2=(a-1)/d;
		long t3=(a-1)/dc;
		
		long ans2=t1+t2-t3;
		//System.out.println(ans2);
		
		System.out.println((b-a+1)-(ans1-ans2));
		
		
	}
	public static int gcd(int num1,int num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    }
}
	 import java.util.Scanner; Scanner 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 dc=d*c/gcd((int)d,(int)c);
		
		long x1=b/c;
		long x2=b/d;
		long x3=b/dc;
		
		long ans1=x1+x2-x3;
		//System.out.println(ans1);
		
		long t1=(a-1)/c;
		long t2=(a-1)/d;
		long t3=(a-1)/dc;
		
		long ans2=t1+t2-t3;
		//System.out.println(ans2);
		
		System.out.println((b-a+1)-(ans1-ans2));
		
		
	}
	public static int gcd(int num1,int num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    }
} 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 dc=d*c/gcd((int)d,(int)c);
		
		long x1=b/c;
		long x2=b/d;
		long x3=b/dc;
		
		long ans1=x1+x2-x3;
		//System.out.println(ans1);
		
		long t1=(a-1)/c;
		long t2=(a-1)/d;
		long t3=(a-1)/dc;
		
		long ans2=t1+t2-t3;
		//System.out.println(ans2);
		
		System.out.println((b-a+1)-(ans1-ans2));
		
		
	} main {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();
		
		
		long dc=d*c/gcd((int)d,(int)c);
		
		long x1=b/c;
		long x2=b/d;
		long x3=b/dc;
		
		long ans1=x1+x2-x3;
		//System.out.println(ans1);
		
		long t1=(a-1)/c;
		long t2=(a-1)/d;
		long t3=(a-1)/dc;
		
		long ans2=t1+t2-t3;
		//System.out.println(ans2);
		
		System.out.println((b-a+1)-(ans1-ans2));
		
		
	} 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 dc=d*c/gcd((int)d,(int)c); dc d*c/gcd((int)d,(int)c) d*c d c gcd((int)d,(int)c) gcd (int)d (int)c long x1=b/c; x1 b/c b c long x2=b/d; x2 b/d b d long x3=b/dc; x3 b/dc b dc long ans1=x1+x2-x3; ans1 x1+x2-x3 x1+x2 x1 x2 x3 long t1=(a-1)/c; t1 (a-1)/c (a-1) a 1 c long t2=(a-1)/d; t2 (a-1)/d (a-1) a 1 d long t3=(a-1)/dc; t3 (a-1)/dc (a-1) a 1 dc long ans2=t1+t2-t3; ans2 t1+t2-t3 t1+t2 t1 t2 t3 System.out.println((b-a+1)-(ans1-ans2)) System.out.println System.out System System.out (b-a+1)-(ans1-ans2) (b-a+1) b-a b a 1 (ans1-ans2) ans1 ans2 String[] args args public static int gcd(int num1,int num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    } gcd {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    } if(num2==0) return num1;
        else return gcd(num2,num1%num2); num2==0 num2 0 return num1; num1 return gcd(num2,num1%num2); gcd(num2,num1%num2) gcd num2 num1%num2 num1 num2 int num1 num1 int num2 num2 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 dc=d*c/gcd((int)d,(int)c);
		
		long x1=b/c;
		long x2=b/d;
		long x3=b/dc;
		
		long ans1=x1+x2-x3;
		//System.out.println(ans1);
		
		long t1=(a-1)/c;
		long t2=(a-1)/d;
		long t3=(a-1)/dc;
		
		long ans2=t1+t2-t3;
		//System.out.println(ans2);
		
		System.out.println((b-a+1)-(ans1-ans2));
		
		
	}
	public static int gcd(int num1,int num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    }
} 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 dc=d*c/gcd((int)d,(int)c);
		
		long x1=b/c;
		long x2=b/d;
		long x3=b/dc;
		
		long ans1=x1+x2-x3;
		//System.out.println(ans1);
		
		long t1=(a-1)/c;
		long t2=(a-1)/d;
		long t3=(a-1)/dc;
		
		long ans2=t1+t2-t3;
		//System.out.println(ans2);
		
		System.out.println((b-a+1)-(ans1-ans2));
		
		
	}
	public static int gcd(int num1,int num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    }
} Main
import java.util.Scanner;
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 dc=d*c/gcd((int)d,(int)c);
		
		long x1=b/c;
		long x2=b/d;
		long x3=b/dc;
		
		long ans1=x1+x2-x3;
		//System.out.println(ans1);
		
		long t1=(a-1)/c;
		long t2=(a-1)/d;
		long t3=(a-1)/dc;
		
		long ans2=t1+t2-t3;
		//System.out.println(ans2);
		
		System.out.println((b-a+1)-(ans1-ans2));
		
		
	}
	public static int gcd(int num1,int num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    }
}
	
