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();
		System.out.println(B-A+1 -(B/C-(A-1)/C+B/D-(A-1)/D-B/lcm(C,D)+(A-1)/lcm(C,D)));
	}
	static long gcd(long C,long D){
		long dai=Math.max(C,D);
		long shou=Math.min(C,D);
		long amari=dai%shou;
		while(amari!=0){
			dai=shou;
			shou=amari;
			amari=dai%shou;
		}
		return shou;
	}
	static long lcm(long C,long D){
		return C*D/gcd(C,D);
	}
}

 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();
		System.out.println(B-A+1 -(B/C-(A-1)/C+B/D-(A-1)/D-B/lcm(C,D)+(A-1)/lcm(C,D)));
	}
	static long gcd(long C,long D){
		long dai=Math.max(C,D);
		long shou=Math.min(C,D);
		long amari=dai%shou;
		while(amari!=0){
			dai=shou;
			shou=amari;
			amari=dai%shou;
		}
		return shou;
	}
	static long lcm(long C,long D){
		return C*D/gcd(C,D);
	}
} 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();
		System.out.println(B-A+1 -(B/C-(A-1)/C+B/D-(A-1)/D-B/lcm(C,D)+(A-1)/lcm(C,D)));
	} main {
		Scanner sc = new Scanner(System.in);
		long A=sc.nextLong();
		long B=sc.nextLong();
		long C=sc.nextLong();
		long D=sc.nextLong();
		System.out.println(B-A+1 -(B/C-(A-1)/C+B/D-(A-1)/D-B/lcm(C,D)+(A-1)/lcm(C,D)));
	} 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 System.out.println(B-A+1 -(B/C-(A-1)/C+B/D-(A-1)/D-B/lcm(C,D)+(A-1)/lcm(C,D))) System.out.println System.out System System.out B-A+1 -(B/C-(A-1)/C+B/D-(A-1)/D-B/lcm(C,D)+(A-1)/lcm(C,D)) B-A+1 B-A B A 1 (B/C-(A-1)/C+B/D-(A-1)/D-B/lcm(C,D)+(A-1)/lcm(C,D)) B/C-(A-1)/C+B/D-(A-1)/D-B/lcm(C,D) B/C-(A-1)/C+B/D-(A-1)/D-B/lcm(C,D) B/C-(A-1)/C+B/D B/C-(A-1)/C B/C B C (A-1)/C (A-1) A 1 C B/D B D (A-1)/D (A-1) A 1 D B/lcm(C,D) B lcm(C,D) lcm C D (A-1)/lcm(C,D) (A-1) A 1 lcm(C,D) lcm C D String[] args args static long gcd(long C,long D){
		long dai=Math.max(C,D);
		long shou=Math.min(C,D);
		long amari=dai%shou;
		while(amari!=0){
			dai=shou;
			shou=amari;
			amari=dai%shou;
		}
		return shou;
	} gcd {
		long dai=Math.max(C,D);
		long shou=Math.min(C,D);
		long amari=dai%shou;
		while(amari!=0){
			dai=shou;
			shou=amari;
			amari=dai%shou;
		}
		return shou;
	} long dai=Math.max(C,D); dai Math.max(C,D) Math.max Math C D long shou=Math.min(C,D); shou Math.min(C,D) Math.min Math C D long amari=dai%shou; amari dai%shou dai shou while(amari!=0){
			dai=shou;
			shou=amari;
			amari=dai%shou;
		} amari!=0 amari 0 {
			dai=shou;
			shou=amari;
			amari=dai%shou;
		} dai=shou dai shou shou=amari shou amari amari=dai%shou amari dai%shou dai shou return shou; shou long C C long D D static long lcm(long C,long D){
		return C*D/gcd(C,D);
	} lcm {
		return C*D/gcd(C,D);
	} return C*D/gcd(C,D); C*D/gcd(C,D) C*D C D gcd(C,D) gcd C D long C C long D D 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();
		System.out.println(B-A+1 -(B/C-(A-1)/C+B/D-(A-1)/D-B/lcm(C,D)+(A-1)/lcm(C,D)));
	}
	static long gcd(long C,long D){
		long dai=Math.max(C,D);
		long shou=Math.min(C,D);
		long amari=dai%shou;
		while(amari!=0){
			dai=shou;
			shou=amari;
			amari=dai%shou;
		}
		return shou;
	}
	static long lcm(long C,long D){
		return C*D/gcd(C,D);
	}
} 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();
		System.out.println(B-A+1 -(B/C-(A-1)/C+B/D-(A-1)/D-B/lcm(C,D)+(A-1)/lcm(C,D)));
	}
	static long gcd(long C,long D){
		long dai=Math.max(C,D);
		long shou=Math.min(C,D);
		long amari=dai%shou;
		while(amari!=0){
			dai=shou;
			shou=amari;
			amari=dai%shou;
		}
		return shou;
	}
	static long lcm(long C,long D){
		return C*D/gcd(C,D);
	}
} 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();
		System.out.println(B-A+1 -(B/C-(A-1)/C+B/D-(A-1)/D-B/lcm(C,D)+(A-1)/lcm(C,D)));
	}
	static long gcd(long C,long D){
		long dai=Math.max(C,D);
		long shou=Math.min(C,D);
		long amari=dai%shou;
		while(amari!=0){
			dai=shou;
			shou=amari;
			amari=dai%shou;
		}
		return shou;
	}
	static long lcm(long C,long D){
		return C*D/gcd(C,D);
	}
}


