import java.util.*;
import java.io.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                PrintWriter ou = new PrintWriter(System.out);
                long a = Long.parseLong(sc.next());
                long b = Long.parseLong(sc.next());
                int c = Integer.parseInt(sc.next());
                int d = Integer.parseInt(sc.next());
                sc.close();
                long cc = c;
                int dd = d;
                while(c % d != 0){
                        int e = c % d;
                        c = d;
                        d = e;
                }
                long s = cc * dd / d;
                a--;
                long yono = b - a - b / cc + a / cc - b / dd + a / dd + b / s - a / s;
                ou.print(yono + "\n");
                ou.flush();
        }
} import java.util.*; util.* java import java.io.*; io.* java public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                PrintWriter ou = new PrintWriter(System.out);
                long a = Long.parseLong(sc.next());
                long b = Long.parseLong(sc.next());
                int c = Integer.parseInt(sc.next());
                int d = Integer.parseInt(sc.next());
                sc.close();
                long cc = c;
                int dd = d;
                while(c % d != 0){
                        int e = c % d;
                        c = d;
                        d = e;
                }
                long s = cc * dd / d;
                a--;
                long yono = b - a - b / cc + a / cc - b / dd + a / dd + b / s - a / s;
                ou.print(yono + "\n");
                ou.flush();
        }
} Main public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                PrintWriter ou = new PrintWriter(System.out);
                long a = Long.parseLong(sc.next());
                long b = Long.parseLong(sc.next());
                int c = Integer.parseInt(sc.next());
                int d = Integer.parseInt(sc.next());
                sc.close();
                long cc = c;
                int dd = d;
                while(c % d != 0){
                        int e = c % d;
                        c = d;
                        d = e;
                }
                long s = cc * dd / d;
                a--;
                long yono = b - a - b / cc + a / cc - b / dd + a / dd + b / s - a / s;
                ou.print(yono + "\n");
                ou.flush();
        } main {
                Scanner sc = new Scanner(System.in);
                PrintWriter ou = new PrintWriter(System.out);
                long a = Long.parseLong(sc.next());
                long b = Long.parseLong(sc.next());
                int c = Integer.parseInt(sc.next());
                int d = Integer.parseInt(sc.next());
                sc.close();
                long cc = c;
                int dd = d;
                while(c % d != 0){
                        int e = c % d;
                        c = d;
                        d = e;
                }
                long s = cc * dd / d;
                a--;
                long yono = b - a - b / cc + a / cc - b / dd + a / dd + b / s - a / s;
                ou.print(yono + "\n");
                ou.flush();
        } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter ou = new PrintWriter(System.out); ou new PrintWriter(System.out) long a = Long.parseLong(sc.next()); a Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long b = Long.parseLong(sc.next()); b Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc int c = Integer.parseInt(sc.next()); c Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int d = Integer.parseInt(sc.next()); d Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sc.close() sc.close sc long cc = c; cc c int dd = d; dd d while(c % d != 0){
                        int e = c % d;
                        c = d;
                        d = e;
                } c % d != 0 c % d c d 0 {
                        int e = c % d;
                        c = d;
                        d = e;
                } int e = c % d; e c % d c d c = d c d d = e d e long s = cc * dd / d; s cc * dd / d cc * dd cc dd d a-- a long yono = b - a - b / cc + a / cc - b / dd + a / dd + b / s - a / s; yono b - a - b / cc + a / cc - b / dd + a / dd + b / s - a / s b - a - b / cc + a / cc - b / dd + a / dd + b / s b - a - b / cc + a / cc - b / dd + a / dd + b / s b - a - b / cc + a / cc - b / dd b - a - b / cc + a / cc b - a - b / cc b - a - b / cc b a b / cc b cc a / cc a cc b / dd b dd a / dd a dd b / s b s a / s a s ou.print(yono + "\n") ou.print ou yono + "\n" yono "\n" ou.flush() ou.flush ou String[] args args public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                PrintWriter ou = new PrintWriter(System.out);
                long a = Long.parseLong(sc.next());
                long b = Long.parseLong(sc.next());
                int c = Integer.parseInt(sc.next());
                int d = Integer.parseInt(sc.next());
                sc.close();
                long cc = c;
                int dd = d;
                while(c % d != 0){
                        int e = c % d;
                        c = d;
                        d = e;
                }
                long s = cc * dd / d;
                a--;
                long yono = b - a - b / cc + a / cc - b / dd + a / dd + b / s - a / s;
                ou.print(yono + "\n");
                ou.flush();
        }
} public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                PrintWriter ou = new PrintWriter(System.out);
                long a = Long.parseLong(sc.next());
                long b = Long.parseLong(sc.next());
                int c = Integer.parseInt(sc.next());
                int d = Integer.parseInt(sc.next());
                sc.close();
                long cc = c;
                int dd = d;
                while(c % d != 0){
                        int e = c % d;
                        c = d;
                        d = e;
                }
                long s = cc * dd / d;
                a--;
                long yono = b - a - b / cc + a / cc - b / dd + a / dd + b / s - a / s;
                ou.print(yono + "\n");
                ou.flush();
        }
} Main
import java.util.*;
import java.io.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                PrintWriter ou = new PrintWriter(System.out);
                long a = Long.parseLong(sc.next());
                long b = Long.parseLong(sc.next());
                int c = Integer.parseInt(sc.next());
                int d = Integer.parseInt(sc.next());
                sc.close();
                long cc = c;
                int dd = d;
                while(c % d != 0){
                        int e = c % d;
                        c = d;
                        d = e;
                }
                long s = cc * dd / d;
                a--;
                long yono = b - a - b / cc + a / cc - b / dd + a / dd + b / s - a / s;
                ou.print(yono + "\n");
                ou.flush();
        }
}