
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
        solve();
    }

    public static void solve(){
        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;

 		count = b - a + 1;
 		count -= (b / c) - (a / c);
 		count -= (b / d) - (a / d);
 		if(b >= c && a % c == 0){
 			count -= 1;
 		}
 		if(b >= d && a % d == 0){
 			count -= 1;
 		}
 		long e = c;
 		long f = d;
 		if(f<e){
 			long temp = f;
 			f = e;
 			e = temp;
 		}
 		while(true){
 			if(e == 0){
 				break;
 			}
 			long x = f % e;
 			f = e;
 			e = x;
 		}
 		count += (b / (c * d / f)) - (a / (c * d / f));
 		if(b >= (c * d / f) && a % (c * d / f) == 0){
 			count += 1;
 		}

 		System.out.println(count);       
    }
} import java.io.*; io.* java import java.util.*; util.* java class Main{
    public static void main(String[] args){
        solve();
    }

    public static void solve(){
        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;

 		count = b - a + 1;
 		count -= (b / c) - (a / c);
 		count -= (b / d) - (a / d);
 		if(b >= c && a % c == 0){
 			count -= 1;
 		}
 		if(b >= d && a % d == 0){
 			count -= 1;
 		}
 		long e = c;
 		long f = d;
 		if(f<e){
 			long temp = f;
 			f = e;
 			e = temp;
 		}
 		while(true){
 			if(e == 0){
 				break;
 			}
 			long x = f % e;
 			f = e;
 			e = x;
 		}
 		count += (b / (c * d / f)) - (a / (c * d / f));
 		if(b >= (c * d / f) && a % (c * d / f) == 0){
 			count += 1;
 		}

 		System.out.println(count);       
    }
} Main public static void main(String[] args){
        solve();
    } main {
        solve();
    } solve() solve String[] args args public static void solve(){
        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;

 		count = b - a + 1;
 		count -= (b / c) - (a / c);
 		count -= (b / d) - (a / d);
 		if(b >= c && a % c == 0){
 			count -= 1;
 		}
 		if(b >= d && a % d == 0){
 			count -= 1;
 		}
 		long e = c;
 		long f = d;
 		if(f<e){
 			long temp = f;
 			f = e;
 			e = temp;
 		}
 		while(true){
 			if(e == 0){
 				break;
 			}
 			long x = f % e;
 			f = e;
 			e = x;
 		}
 		count += (b / (c * d / f)) - (a / (c * d / f));
 		if(b >= (c * d / f) && a % (c * d / f) == 0){
 			count += 1;
 		}

 		System.out.println(count);       
    } solve {
        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;

 		count = b - a + 1;
 		count -= (b / c) - (a / c);
 		count -= (b / d) - (a / d);
 		if(b >= c && a % c == 0){
 			count -= 1;
 		}
 		if(b >= d && a % d == 0){
 			count -= 1;
 		}
 		long e = c;
 		long f = d;
 		if(f<e){
 			long temp = f;
 			f = e;
 			e = temp;
 		}
 		while(true){
 			if(e == 0){
 				break;
 			}
 			long x = f % e;
 			f = e;
 			e = x;
 		}
 		count += (b / (c * d / f)) - (a / (c * d / f));
 		if(b >= (c * d / f) && a % (c * d / f) == 0){
 			count += 1;
 		}

 		System.out.println(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 count = b - a + 1 count b - a + 1 b - a b a 1 count -= (b / c) - (a / c) count (b / c) - (a / c) (b / c) b c (a / c) a c count -= (b / d) - (a / d) count (b / d) - (a / d) (b / d) b d (a / d) a d if(b >= c && a % c == 0){
 			count -= 1;
 		} b >= c && a % c == 0 b >= c b c a % c == 0 a % c a c 0 {
 			count -= 1;
 		} count -= 1 count 1 if(b >= d && a % d == 0){
 			count -= 1;
 		} b >= d && a % d == 0 b >= d b d a % d == 0 a % d a d 0 {
 			count -= 1;
 		} count -= 1 count 1 long e = c; e c long f = d; f d if(f<e){
 			long temp = f;
 			f = e;
 			e = temp;
 		} f<e f e {
 			long temp = f;
 			f = e;
 			e = temp;
 		} long temp = f; temp f f = e f e e = temp e temp while(true){
 			if(e == 0){
 				break;
 			}
 			long x = f % e;
 			f = e;
 			e = x;
 		} true {
 			if(e == 0){
 				break;
 			}
 			long x = f % e;
 			f = e;
 			e = x;
 		} if(e == 0){
 				break;
 			} e == 0 e 0 {
 				break;
 			} break; long x = f % e; x f % e f e f = e f e e = x e x count += (b / (c * d / f)) - (a / (c * d / f)) count (b / (c * d / f)) - (a / (c * d / f)) (b / (c * d / f)) b (c * d / f) c * d c d f (a / (c * d / f)) a (c * d / f) c * d c d f if(b >= (c * d / f) && a % (c * d / f) == 0){
 			count += 1;
 		} b >= (c * d / f) && a % (c * d / f) == 0 b >= (c * d / f) b (c * d / f) c * d c d f a % (c * d / f) == 0 a % (c * d / f) a (c * d / f) c * d c d f 0 {
 			count += 1;
 		} count += 1 count 1 System.out.println(count) System.out.println System.out System System.out count

import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
        solve();
    }

    public static void solve(){
        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;

 		count = b - a + 1;
 		count -= (b / c) - (a / c);
 		count -= (b / d) - (a / d);
 		if(b >= c && a % c == 0){
 			count -= 1;
 		}
 		if(b >= d && a % d == 0){
 			count -= 1;
 		}
 		long e = c;
 		long f = d;
 		if(f<e){
 			long temp = f;
 			f = e;
 			e = temp;
 		}
 		while(true){
 			if(e == 0){
 				break;
 			}
 			long x = f % e;
 			f = e;
 			e = x;
 		}
 		count += (b / (c * d / f)) - (a / (c * d / f));
 		if(b >= (c * d / f) && a % (c * d / f) == 0){
 			count += 1;
 		}

 		System.out.println(count);       
    }
}