import java.util.*;
public class Main {
    public static long greatestCommonDiv(long c, long d) {
        if (d > c) {
            long temp = c;
            c = d;
            d = temp;
        }
        if (d == 0) return c;
        return greatestCommonDiv(d, c%d);
    }
    public static long leastCommonMul(long c, long d) {
        return (c*d) / greatestCommonDiv(c, d);
    }
    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 ac = (a-1)/c;
        long bc = b/c;
        long ad = (a-1)/d;
        long bd = b/d;
        long lcm = leastCommonMul(c, d);
        long blcm = b/lcm;
        long alcm = (a-1)/lcm;
        long res = b - a + 1 - (bc - ac + bd - ad - blcm + alcm);
        System.out.println(res);
    }
} import java.util.*; util.* java public class Main {
    public static long greatestCommonDiv(long c, long d) {
        if (d > c) {
            long temp = c;
            c = d;
            d = temp;
        }
        if (d == 0) return c;
        return greatestCommonDiv(d, c%d);
    }
    public static long leastCommonMul(long c, long d) {
        return (c*d) / greatestCommonDiv(c, d);
    }
    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 ac = (a-1)/c;
        long bc = b/c;
        long ad = (a-1)/d;
        long bd = b/d;
        long lcm = leastCommonMul(c, d);
        long blcm = b/lcm;
        long alcm = (a-1)/lcm;
        long res = b - a + 1 - (bc - ac + bd - ad - blcm + alcm);
        System.out.println(res);
    }
} Main public static long greatestCommonDiv(long c, long d) {
        if (d > c) {
            long temp = c;
            c = d;
            d = temp;
        }
        if (d == 0) return c;
        return greatestCommonDiv(d, c%d);
    } greatestCommonDiv {
        if (d > c) {
            long temp = c;
            c = d;
            d = temp;
        }
        if (d == 0) return c;
        return greatestCommonDiv(d, c%d);
    } if (d > c) {
            long temp = c;
            c = d;
            d = temp;
        } d > c d c {
            long temp = c;
            c = d;
            d = temp;
        } long temp = c; temp c c = d c d d = temp d temp if (d == 0) return c; d == 0 d 0 return c; c return greatestCommonDiv(d, c%d); greatestCommonDiv(d, c%d) greatestCommonDiv d c%d c d long c c long d d public static long leastCommonMul(long c, long d) {
        return (c*d) / greatestCommonDiv(c, d);
    } leastCommonMul {
        return (c*d) / greatestCommonDiv(c, d);
    } return (c*d) / greatestCommonDiv(c, d); (c*d) / greatestCommonDiv(c, d) (c*d) c d greatestCommonDiv(c, d) greatestCommonDiv c d long c c long d d 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 ac = (a-1)/c;
        long bc = b/c;
        long ad = (a-1)/d;
        long bd = b/d;
        long lcm = leastCommonMul(c, d);
        long blcm = b/lcm;
        long alcm = (a-1)/lcm;
        long res = b - a + 1 - (bc - ac + bd - ad - blcm + alcm);
        System.out.println(res);
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long ac = (a-1)/c;
        long bc = b/c;
        long ad = (a-1)/d;
        long bd = b/d;
        long lcm = leastCommonMul(c, d);
        long blcm = b/lcm;
        long alcm = (a-1)/lcm;
        long res = b - a + 1 - (bc - ac + bd - ad - blcm + alcm);
        System.out.println(res);
    } 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 ac = (a-1)/c; ac (a-1)/c (a-1) a 1 c long bc = b/c; bc b/c b c long ad = (a-1)/d; ad (a-1)/d (a-1) a 1 d long bd = b/d; bd b/d b d long lcm = leastCommonMul(c, d); lcm leastCommonMul(c, d) leastCommonMul c d long blcm = b/lcm; blcm b/lcm b lcm long alcm = (a-1)/lcm; alcm (a-1)/lcm (a-1) a 1 lcm long res = b - a + 1 - (bc - ac + bd - ad - blcm + alcm); res b - a + 1 - (bc - ac + bd - ad - blcm + alcm) b - a + 1 b - a b a 1 (bc - ac + bd - ad - blcm + alcm) bc - ac + bd - ad - blcm bc - ac + bd - ad - blcm bc - ac + bd bc - ac bc ac bd ad blcm alcm System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main {
    public static long greatestCommonDiv(long c, long d) {
        if (d > c) {
            long temp = c;
            c = d;
            d = temp;
        }
        if (d == 0) return c;
        return greatestCommonDiv(d, c%d);
    }
    public static long leastCommonMul(long c, long d) {
        return (c*d) / greatestCommonDiv(c, d);
    }
    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 ac = (a-1)/c;
        long bc = b/c;
        long ad = (a-1)/d;
        long bd = b/d;
        long lcm = leastCommonMul(c, d);
        long blcm = b/lcm;
        long alcm = (a-1)/lcm;
        long res = b - a + 1 - (bc - ac + bd - ad - blcm + alcm);
        System.out.println(res);
    }
} public class Main {
    public static long greatestCommonDiv(long c, long d) {
        if (d > c) {
            long temp = c;
            c = d;
            d = temp;
        }
        if (d == 0) return c;
        return greatestCommonDiv(d, c%d);
    }
    public static long leastCommonMul(long c, long d) {
        return (c*d) / greatestCommonDiv(c, d);
    }
    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 ac = (a-1)/c;
        long bc = b/c;
        long ad = (a-1)/d;
        long bd = b/d;
        long lcm = leastCommonMul(c, d);
        long blcm = b/lcm;
        long alcm = (a-1)/lcm;
        long res = b - a + 1 - (bc - ac + bd - ad - blcm + alcm);
        System.out.println(res);
    }
} Main
import java.util.*;
public class Main {
    public static long greatestCommonDiv(long c, long d) {
        if (d > c) {
            long temp = c;
            c = d;
            d = temp;
        }
        if (d == 0) return c;
        return greatestCommonDiv(d, c%d);
    }
    public static long leastCommonMul(long c, long d) {
        return (c*d) / greatestCommonDiv(c, d);
    }
    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 ac = (a-1)/c;
        long bc = b/c;
        long ad = (a-1)/d;
        long bd = b/d;
        long lcm = leastCommonMul(c, d);
        long blcm = b/lcm;
        long alcm = (a-1)/lcm;
        long res = b - a + 1 - (bc - ac + bd - ad - blcm + alcm);
        System.out.println(res);
    }
}