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 c = 0;
		long d = 0;
		long cd = 0;
		
		long koub = 0;
		
		koub = C * D / gcd(C, D);
		
		if(A == B) {
			if(A % C != 0 && A % D != 0) {
				System.out.println(1);
				return;
			} else {
				System.out.println(0);
				return;
			}
		}
		
		if(C == D) {
			long x = 0;
			if(A % C != 0) {
				x = (B - (A / C + 1) * C) / C + 1;
			} else {
				x = (B - A) / C + 1;
			}
			System.out.println(B - A + 1 - x);
			return;
		}
		
	
		if(A % C != 0) {
			if(A > C) {
				c = (B - (A / C + 1) * C) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		} else {
			if(A > C) {
				c = (B - A) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		}
		
		if(A % D != 0) {
			if(A > D) {
				d = (B - (A / D + 1) * D) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		} else {
			if(A > D) {
				d = (B - A) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		}
		
		if(A % koub != 0) {
			if(A > koub) {
				cd = (B - (A / koub + 1) * koub) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		} else {
			if(A > koub) {
				cd = (B - A) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		}
		
		System.out.println(B - A + 1 - c - d + cd);
	}
	
	public static long gcd(long a, long b) {
		if(b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}
} 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 c = 0;
		long d = 0;
		long cd = 0;
		
		long koub = 0;
		
		koub = C * D / gcd(C, D);
		
		if(A == B) {
			if(A % C != 0 && A % D != 0) {
				System.out.println(1);
				return;
			} else {
				System.out.println(0);
				return;
			}
		}
		
		if(C == D) {
			long x = 0;
			if(A % C != 0) {
				x = (B - (A / C + 1) * C) / C + 1;
			} else {
				x = (B - A) / C + 1;
			}
			System.out.println(B - A + 1 - x);
			return;
		}
		
	
		if(A % C != 0) {
			if(A > C) {
				c = (B - (A / C + 1) * C) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		} else {
			if(A > C) {
				c = (B - A) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		}
		
		if(A % D != 0) {
			if(A > D) {
				d = (B - (A / D + 1) * D) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		} else {
			if(A > D) {
				d = (B - A) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		}
		
		if(A % koub != 0) {
			if(A > koub) {
				cd = (B - (A / koub + 1) * koub) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		} else {
			if(A > koub) {
				cd = (B - A) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		}
		
		System.out.println(B - A + 1 - c - d + cd);
	}
	
	public 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 c = 0;
		long d = 0;
		long cd = 0;
		
		long koub = 0;
		
		koub = C * D / gcd(C, D);
		
		if(A == B) {
			if(A % C != 0 && A % D != 0) {
				System.out.println(1);
				return;
			} else {
				System.out.println(0);
				return;
			}
		}
		
		if(C == D) {
			long x = 0;
			if(A % C != 0) {
				x = (B - (A / C + 1) * C) / C + 1;
			} else {
				x = (B - A) / C + 1;
			}
			System.out.println(B - A + 1 - x);
			return;
		}
		
	
		if(A % C != 0) {
			if(A > C) {
				c = (B - (A / C + 1) * C) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		} else {
			if(A > C) {
				c = (B - A) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		}
		
		if(A % D != 0) {
			if(A > D) {
				d = (B - (A / D + 1) * D) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		} else {
			if(A > D) {
				d = (B - A) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		}
		
		if(A % koub != 0) {
			if(A > koub) {
				cd = (B - (A / koub + 1) * koub) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		} else {
			if(A > koub) {
				cd = (B - A) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		}
		
		System.out.println(B - A + 1 - c - d + cd);
	} main {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		
		long c = 0;
		long d = 0;
		long cd = 0;
		
		long koub = 0;
		
		koub = C * D / gcd(C, D);
		
		if(A == B) {
			if(A % C != 0 && A % D != 0) {
				System.out.println(1);
				return;
			} else {
				System.out.println(0);
				return;
			}
		}
		
		if(C == D) {
			long x = 0;
			if(A % C != 0) {
				x = (B - (A / C + 1) * C) / C + 1;
			} else {
				x = (B - A) / C + 1;
			}
			System.out.println(B - A + 1 - x);
			return;
		}
		
	
		if(A % C != 0) {
			if(A > C) {
				c = (B - (A / C + 1) * C) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		} else {
			if(A > C) {
				c = (B - A) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		}
		
		if(A % D != 0) {
			if(A > D) {
				d = (B - (A / D + 1) * D) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		} else {
			if(A > D) {
				d = (B - A) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		}
		
		if(A % koub != 0) {
			if(A > koub) {
				cd = (B - (A / koub + 1) * koub) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		} else {
			if(A > koub) {
				cd = (B - A) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		}
		
		System.out.println(B - A + 1 - c - d + cd);
	} 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 c = 0; c 0 long d = 0; d 0 long cd = 0; cd 0 long koub = 0; koub 0 koub = C * D / gcd(C, D) koub C * D / gcd(C, D) C * D C D gcd(C, D) gcd C D if(A == B) {
			if(A % C != 0 && A % D != 0) {
				System.out.println(1);
				return;
			} else {
				System.out.println(0);
				return;
			}
		} A == B A B {
			if(A % C != 0 && A % D != 0) {
				System.out.println(1);
				return;
			} else {
				System.out.println(0);
				return;
			}
		} if(A % C != 0 && A % D != 0) {
				System.out.println(1);
				return;
			} else {
				System.out.println(0);
				return;
			} 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(1);
				return;
			} System.out.println(1) System.out.println System.out System System.out 1 return; {
				System.out.println(0);
				return;
			} System.out.println(0) System.out.println System.out System System.out 0 return; if(C == D) {
			long x = 0;
			if(A % C != 0) {
				x = (B - (A / C + 1) * C) / C + 1;
			} else {
				x = (B - A) / C + 1;
			}
			System.out.println(B - A + 1 - x);
			return;
		} C == D C D {
			long x = 0;
			if(A % C != 0) {
				x = (B - (A / C + 1) * C) / C + 1;
			} else {
				x = (B - A) / C + 1;
			}
			System.out.println(B - A + 1 - x);
			return;
		} long x = 0; x 0 if(A % C != 0) {
				x = (B - (A / C + 1) * C) / C + 1;
			} else {
				x = (B - A) / C + 1;
			} A % C != 0 A % C A C 0 {
				x = (B - (A / C + 1) * C) / C + 1;
			} x = (B - (A / C + 1) * C) / C + 1 x (B - (A / C + 1) * C) / C + 1 (B - (A / C + 1) * C) / C (B - (A / C + 1) * C) B (A / C + 1) * C (A / C + 1) A / C A C 1 C C 1 {
				x = (B - A) / C + 1;
			} x = (B - A) / C + 1 x (B - A) / C + 1 (B - A) / C (B - A) B A C 1 System.out.println(B - A + 1 - x) System.out.println System.out System System.out B - A + 1 - x B - A + 1 B - A B A 1 x return; if(A % C != 0) {
			if(A > C) {
				c = (B - (A / C + 1) * C) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		} else {
			if(A > C) {
				c = (B - A) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		} A % C != 0 A % C A C 0 {
			if(A > C) {
				c = (B - (A / C + 1) * C) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		} if(A > C) {
				c = (B - (A / C + 1) * C) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			} A > C A C {
				c = (B - (A / C + 1) * C) / C + 1;
			} c = (B - (A / C + 1) * C) / C + 1 c (B - (A / C + 1) * C) / C + 1 (B - (A / C + 1) * C) / C (B - (A / C + 1) * C) B (A / C + 1) * C (A / C + 1) A / C A C 1 C C 1 {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			} if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				} C <= B C B {
					c = (B - C) / C + 1;
				} c = (B - C) / C + 1 c (B - C) / C + 1 (B - C) / C (B - C) B C C 1 {
					c = 0;
				} c = 0 c 0 {
			if(A > C) {
				c = (B - A) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		} if(A > C) {
				c = (B - A) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			} A > C A C {
				c = (B - A) / C + 1;
			} c = (B - A) / C + 1 c (B - A) / C + 1 (B - A) / C (B - A) B A C 1 {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			} if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				} C <= B C B {
					c = (B - C) / C + 1;
				} c = (B - C) / C + 1 c (B - C) / C + 1 (B - C) / C (B - C) B C C 1 {
					c = 0;
				} c = 0 c 0 if(A % D != 0) {
			if(A > D) {
				d = (B - (A / D + 1) * D) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		} else {
			if(A > D) {
				d = (B - A) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		} A % D != 0 A % D A D 0 {
			if(A > D) {
				d = (B - (A / D + 1) * D) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		} if(A > D) {
				d = (B - (A / D + 1) * D) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			} A > D A D {
				d = (B - (A / D + 1) * D) / D + 1;
			} d = (B - (A / D + 1) * D) / D + 1 d (B - (A / D + 1) * D) / D + 1 (B - (A / D + 1) * D) / D (B - (A / D + 1) * D) B (A / D + 1) * D (A / D + 1) A / D A D 1 D D 1 {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			} if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				} D <= B D B {
					d = (B - D) / D + 1;
				} d = (B - D) / D + 1 d (B - D) / D + 1 (B - D) / D (B - D) B D D 1 {
					d = 0;
				} d = 0 d 0 {
			if(A > D) {
				d = (B - A) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		} if(A > D) {
				d = (B - A) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			} A > D A D {
				d = (B - A) / D + 1;
			} d = (B - A) / D + 1 d (B - A) / D + 1 (B - A) / D (B - A) B A D 1 {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			} if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				} D <= B D B {
					d = (B - D) / D + 1;
				} d = (B - D) / D + 1 d (B - D) / D + 1 (B - D) / D (B - D) B D D 1 {
					d = 0;
				} d = 0 d 0 if(A % koub != 0) {
			if(A > koub) {
				cd = (B - (A / koub + 1) * koub) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		} else {
			if(A > koub) {
				cd = (B - A) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		} A % koub != 0 A % koub A koub 0 {
			if(A > koub) {
				cd = (B - (A / koub + 1) * koub) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		} if(A > koub) {
				cd = (B - (A / koub + 1) * koub) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			} A > koub A koub {
				cd = (B - (A / koub + 1) * koub) / koub + 1;
			} cd = (B - (A / koub + 1) * koub) / koub + 1 cd (B - (A / koub + 1) * koub) / koub + 1 (B - (A / koub + 1) * koub) / koub (B - (A / koub + 1) * koub) B (A / koub + 1) * koub (A / koub + 1) A / koub A koub 1 koub koub 1 {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			} if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				} koub <= B koub B {
					cd = (B - koub) / koub + 1;
				} cd = (B - koub) / koub + 1 cd (B - koub) / koub + 1 (B - koub) / koub (B - koub) B koub koub 1 {
					cd = 0;
				} cd = 0 cd 0 {
			if(A > koub) {
				cd = (B - A) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		} if(A > koub) {
				cd = (B - A) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			} A > koub A koub {
				cd = (B - A) / koub + 1;
			} cd = (B - A) / koub + 1 cd (B - A) / koub + 1 (B - A) / koub (B - A) B A koub 1 {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			} if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				} koub <= B koub B {
					cd = (B - koub) / koub + 1;
				} cd = (B - koub) / koub + 1 cd (B - koub) / koub + 1 (B - koub) / koub (B - koub) B koub koub 1 {
					cd = 0;
				} cd = 0 cd 0 System.out.println(B - A + 1 - c - d + cd) System.out.println System.out System System.out B - A + 1 - c - d + cd B - A + 1 - c - d B - A + 1 - c - d B - A + 1 B - A B A 1 c d cd String[] args args public 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;
		} 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 c = 0;
		long d = 0;
		long cd = 0;
		
		long koub = 0;
		
		koub = C * D / gcd(C, D);
		
		if(A == B) {
			if(A % C != 0 && A % D != 0) {
				System.out.println(1);
				return;
			} else {
				System.out.println(0);
				return;
			}
		}
		
		if(C == D) {
			long x = 0;
			if(A % C != 0) {
				x = (B - (A / C + 1) * C) / C + 1;
			} else {
				x = (B - A) / C + 1;
			}
			System.out.println(B - A + 1 - x);
			return;
		}
		
	
		if(A % C != 0) {
			if(A > C) {
				c = (B - (A / C + 1) * C) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		} else {
			if(A > C) {
				c = (B - A) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		}
		
		if(A % D != 0) {
			if(A > D) {
				d = (B - (A / D + 1) * D) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		} else {
			if(A > D) {
				d = (B - A) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		}
		
		if(A % koub != 0) {
			if(A > koub) {
				cd = (B - (A / koub + 1) * koub) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		} else {
			if(A > koub) {
				cd = (B - A) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		}
		
		System.out.println(B - A + 1 - c - d + cd);
	}
	
	public 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 c = 0;
		long d = 0;
		long cd = 0;
		
		long koub = 0;
		
		koub = C * D / gcd(C, D);
		
		if(A == B) {
			if(A % C != 0 && A % D != 0) {
				System.out.println(1);
				return;
			} else {
				System.out.println(0);
				return;
			}
		}
		
		if(C == D) {
			long x = 0;
			if(A % C != 0) {
				x = (B - (A / C + 1) * C) / C + 1;
			} else {
				x = (B - A) / C + 1;
			}
			System.out.println(B - A + 1 - x);
			return;
		}
		
	
		if(A % C != 0) {
			if(A > C) {
				c = (B - (A / C + 1) * C) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		} else {
			if(A > C) {
				c = (B - A) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		}
		
		if(A % D != 0) {
			if(A > D) {
				d = (B - (A / D + 1) * D) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		} else {
			if(A > D) {
				d = (B - A) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		}
		
		if(A % koub != 0) {
			if(A > koub) {
				cd = (B - (A / koub + 1) * koub) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		} else {
			if(A > koub) {
				cd = (B - A) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		}
		
		System.out.println(B - A + 1 - c - d + cd);
	}
	
	public static long gcd(long a, long b) {
		if(b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}
} 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 c = 0;
		long d = 0;
		long cd = 0;
		
		long koub = 0;
		
		koub = C * D / gcd(C, D);
		
		if(A == B) {
			if(A % C != 0 && A % D != 0) {
				System.out.println(1);
				return;
			} else {
				System.out.println(0);
				return;
			}
		}
		
		if(C == D) {
			long x = 0;
			if(A % C != 0) {
				x = (B - (A / C + 1) * C) / C + 1;
			} else {
				x = (B - A) / C + 1;
			}
			System.out.println(B - A + 1 - x);
			return;
		}
		
	
		if(A % C != 0) {
			if(A > C) {
				c = (B - (A / C + 1) * C) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		} else {
			if(A > C) {
				c = (B - A) / C + 1;
			} else {
				if(C <= B) {
					c = (B - C) / C + 1;
				} else {
					c = 0;
				}
			}
		}
		
		if(A % D != 0) {
			if(A > D) {
				d = (B - (A / D + 1) * D) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		} else {
			if(A > D) {
				d = (B - A) / D + 1;
			} else {
				if(D <= B) {
					d = (B - D) / D + 1;
				} else {
					d = 0;
				}
			}
		}
		
		if(A % koub != 0) {
			if(A > koub) {
				cd = (B - (A / koub + 1) * koub) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		} else {
			if(A > koub) {
				cd = (B - A) / koub + 1;
			} else {
				if(koub <= B) {
					cd = (B - koub) / koub + 1;
				} else {
					cd = 0;
				}
			}
		}
		
		System.out.println(B - A + 1 - c - d + cd);
	}
	
	public static long gcd(long a, long b) {
		if(b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}
}
