import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      long A = in.nextLong();
      long B = in.nextLong();
      long C = in.nextLong();
      long D = in.nextLong();
      long countDivideByC = count(A, B, C);
      long countDivideByD = count(A, B, D);
      long countDivideByLCM_CD = count (A, B, C * D / gcd(C, D));
      
      System.out.println(B - A + 1 - countDivideByC - countDivideByD + countDivideByLCM_CD);
    }
  }

  private static long count (long start, long end, long div) {
    return end / div - start / div + (start % div == 0 ? 1 : 0);
  }

  private static long gcd (long a, long b) {
    return b == 0 ? a : gcd(b, a % b);
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      long A = in.nextLong();
      long B = in.nextLong();
      long C = in.nextLong();
      long D = in.nextLong();
      long countDivideByC = count(A, B, C);
      long countDivideByD = count(A, B, D);
      long countDivideByLCM_CD = count (A, B, C * D / gcd(C, D));
      
      System.out.println(B - A + 1 - countDivideByC - countDivideByD + countDivideByLCM_CD);
    }
  }

  private static long count (long start, long end, long div) {
    return end / div - start / div + (start % div == 0 ? 1 : 0);
  }

  private static long gcd (long a, long b) {
    return b == 0 ? a : gcd(b, a % b);
  }
} Main public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      long A = in.nextLong();
      long B = in.nextLong();
      long C = in.nextLong();
      long D = in.nextLong();
      long countDivideByC = count(A, B, C);
      long countDivideByD = count(A, B, D);
      long countDivideByLCM_CD = count (A, B, C * D / gcd(C, D));
      
      System.out.println(B - A + 1 - countDivideByC - countDivideByD + countDivideByLCM_CD);
    }
  } main {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      long A = in.nextLong();
      long B = in.nextLong();
      long C = in.nextLong();
      long D = in.nextLong();
      long countDivideByC = count(A, B, C);
      long countDivideByD = count(A, B, D);
      long countDivideByLCM_CD = count (A, B, C * D / gcd(C, D));
      
      System.out.println(B - A + 1 - countDivideByC - countDivideByD + countDivideByLCM_CD);
    }
  } Scanner in = new Scanner(System.in); in new Scanner(System.in) while (in.hasNext()) {
      long A = in.nextLong();
      long B = in.nextLong();
      long C = in.nextLong();
      long D = in.nextLong();
      long countDivideByC = count(A, B, C);
      long countDivideByD = count(A, B, D);
      long countDivideByLCM_CD = count (A, B, C * D / gcd(C, D));
      
      System.out.println(B - A + 1 - countDivideByC - countDivideByD + countDivideByLCM_CD);
    } in.hasNext() in.hasNext in {
      long A = in.nextLong();
      long B = in.nextLong();
      long C = in.nextLong();
      long D = in.nextLong();
      long countDivideByC = count(A, B, C);
      long countDivideByD = count(A, B, D);
      long countDivideByLCM_CD = count (A, B, C * D / gcd(C, D));
      
      System.out.println(B - A + 1 - countDivideByC - countDivideByD + countDivideByLCM_CD);
    } long A = in.nextLong(); A in.nextLong() in.nextLong in long B = in.nextLong(); B in.nextLong() in.nextLong in long C = in.nextLong(); C in.nextLong() in.nextLong in long D = in.nextLong(); D in.nextLong() in.nextLong in long countDivideByC = count(A, B, C); countDivideByC count(A, B, C) count A B C long countDivideByD = count(A, B, D); countDivideByD count(A, B, D) count A B D long countDivideByLCM_CD = count (A, B, C * D / gcd(C, D)); countDivideByLCM_CD count (A, B, C * D / gcd(C, D)) count A B C * D / gcd(C, D) C * D C D gcd(C, D) gcd C D System.out.println(B - A + 1 - countDivideByC - countDivideByD + countDivideByLCM_CD) System.out.println System.out System System.out B - A + 1 - countDivideByC - countDivideByD + countDivideByLCM_CD B - A + 1 - countDivideByC - countDivideByD B - A + 1 - countDivideByC - countDivideByD B - A + 1 B - A B A 1 countDivideByC countDivideByD countDivideByLCM_CD String[] args args private static long count (long start, long end, long div) {
    return end / div - start / div + (start % div == 0 ? 1 : 0);
  } count {
    return end / div - start / div + (start % div == 0 ? 1 : 0);
  } return end / div - start / div + (start % div == 0 ? 1 : 0); end / div - start / div + (start % div == 0 ? 1 : 0) end / div - start / div end / div end div start / div start div (start % div == 0 ? 1 : 0) start % div == 0 start % div start div 0 1 0 long start start long end end long div div private static long gcd (long a, long b) {
    return b == 0 ? a : gcd(b, a % b);
  } gcd {
    return b == 0 ? a : gcd(b, a % b);
  } return b == 0 ? a : gcd(b, a % b); b == 0 ? a : gcd(b, a % b) b == 0 b 0 a 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 in = new Scanner(System.in);

    while (in.hasNext()) {
      long A = in.nextLong();
      long B = in.nextLong();
      long C = in.nextLong();
      long D = in.nextLong();
      long countDivideByC = count(A, B, C);
      long countDivideByD = count(A, B, D);
      long countDivideByLCM_CD = count (A, B, C * D / gcd(C, D));
      
      System.out.println(B - A + 1 - countDivideByC - countDivideByD + countDivideByLCM_CD);
    }
  }

  private static long count (long start, long end, long div) {
    return end / div - start / div + (start % div == 0 ? 1 : 0);
  }

  private static long gcd (long a, long b) {
    return b == 0 ? a : gcd(b, a % b);
  }
} public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      long A = in.nextLong();
      long B = in.nextLong();
      long C = in.nextLong();
      long D = in.nextLong();
      long countDivideByC = count(A, B, C);
      long countDivideByD = count(A, B, D);
      long countDivideByLCM_CD = count (A, B, C * D / gcd(C, D));
      
      System.out.println(B - A + 1 - countDivideByC - countDivideByD + countDivideByLCM_CD);
    }
  }

  private static long count (long start, long end, long div) {
    return end / div - start / div + (start % div == 0 ? 1 : 0);
  }

  private static long gcd (long a, long b) {
    return b == 0 ? a : gcd(b, a % b);
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      long A = in.nextLong();
      long B = in.nextLong();
      long C = in.nextLong();
      long D = in.nextLong();
      long countDivideByC = count(A, B, C);
      long countDivideByD = count(A, B, D);
      long countDivideByLCM_CD = count (A, B, C * D / gcd(C, D));
      
      System.out.println(B - A + 1 - countDivideByC - countDivideByD + countDivideByLCM_CD);
    }
  }

  private static long count (long start, long end, long div) {
    return end / div - start / div + (start % div == 0 ? 1 : 0);
  }

  private static long gcd (long a, long b) {
    return b == 0 ? a : gcd(b, a % b);
  }
}