import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    long A = scn.nextLong();
    long B = scn.nextLong();
    long C = scn.nextLong();
    long D = scn.nextLong();

    long multiple_C_num = (A - 1) / C;
    long multiple_D_num = (A - 1) / D;
    long multiple_CD_num = multiple_C_num + multiple_D_num - ((A - 1) / lcm(C, D));
    long notMultiple_num_A = (A - 1) - multiple_CD_num;
    if (notMultiple_num_A < 0) {
      notMultiple_num_A = 0;
    }

    multiple_C_num = B / C;
    multiple_D_num = B / D;
    multiple_CD_num = multiple_C_num + multiple_D_num - (B / lcm(C, D));
    long notMultiple_num_B = B - multiple_CD_num;
    if (notMultiple_num_B < 0) {
      notMultiple_num_B = 0;
    }

    System.out.println(notMultiple_num_B - notMultiple_num_A);

  }

  public static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);

  }

  public static long lcm(long a, long b) {
    return (a * b) / gcd(a, b);
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    long A = scn.nextLong();
    long B = scn.nextLong();
    long C = scn.nextLong();
    long D = scn.nextLong();

    long multiple_C_num = (A - 1) / C;
    long multiple_D_num = (A - 1) / D;
    long multiple_CD_num = multiple_C_num + multiple_D_num - ((A - 1) / lcm(C, D));
    long notMultiple_num_A = (A - 1) - multiple_CD_num;
    if (notMultiple_num_A < 0) {
      notMultiple_num_A = 0;
    }

    multiple_C_num = B / C;
    multiple_D_num = B / D;
    multiple_CD_num = multiple_C_num + multiple_D_num - (B / lcm(C, D));
    long notMultiple_num_B = B - multiple_CD_num;
    if (notMultiple_num_B < 0) {
      notMultiple_num_B = 0;
    }

    System.out.println(notMultiple_num_B - notMultiple_num_A);

  }

  public static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);

  }

  public static long lcm(long a, long b) {
    return (a * b) / gcd(a, b);
  }
} Main public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    long A = scn.nextLong();
    long B = scn.nextLong();
    long C = scn.nextLong();
    long D = scn.nextLong();

    long multiple_C_num = (A - 1) / C;
    long multiple_D_num = (A - 1) / D;
    long multiple_CD_num = multiple_C_num + multiple_D_num - ((A - 1) / lcm(C, D));
    long notMultiple_num_A = (A - 1) - multiple_CD_num;
    if (notMultiple_num_A < 0) {
      notMultiple_num_A = 0;
    }

    multiple_C_num = B / C;
    multiple_D_num = B / D;
    multiple_CD_num = multiple_C_num + multiple_D_num - (B / lcm(C, D));
    long notMultiple_num_B = B - multiple_CD_num;
    if (notMultiple_num_B < 0) {
      notMultiple_num_B = 0;
    }

    System.out.println(notMultiple_num_B - notMultiple_num_A);

  } main {
    Scanner scn = new Scanner(System.in);
    long A = scn.nextLong();
    long B = scn.nextLong();
    long C = scn.nextLong();
    long D = scn.nextLong();

    long multiple_C_num = (A - 1) / C;
    long multiple_D_num = (A - 1) / D;
    long multiple_CD_num = multiple_C_num + multiple_D_num - ((A - 1) / lcm(C, D));
    long notMultiple_num_A = (A - 1) - multiple_CD_num;
    if (notMultiple_num_A < 0) {
      notMultiple_num_A = 0;
    }

    multiple_C_num = B / C;
    multiple_D_num = B / D;
    multiple_CD_num = multiple_C_num + multiple_D_num - (B / lcm(C, D));
    long notMultiple_num_B = B - multiple_CD_num;
    if (notMultiple_num_B < 0) {
      notMultiple_num_B = 0;
    }

    System.out.println(notMultiple_num_B - notMultiple_num_A);

  } Scanner scn = new Scanner(System.in); scn new Scanner(System.in) long A = scn.nextLong(); A scn.nextLong() scn.nextLong scn long B = scn.nextLong(); B scn.nextLong() scn.nextLong scn long C = scn.nextLong(); C scn.nextLong() scn.nextLong scn long D = scn.nextLong(); D scn.nextLong() scn.nextLong scn long multiple_C_num = (A - 1) / C; multiple_C_num (A - 1) / C (A - 1) A 1 C long multiple_D_num = (A - 1) / D; multiple_D_num (A - 1) / D (A - 1) A 1 D long multiple_CD_num = multiple_C_num + multiple_D_num - ((A - 1) / lcm(C, D)); multiple_CD_num multiple_C_num + multiple_D_num - ((A - 1) / lcm(C, D)) multiple_C_num + multiple_D_num multiple_C_num multiple_D_num ((A - 1) / lcm(C, D)) (A - 1) A 1 lcm(C, D) lcm C D long notMultiple_num_A = (A - 1) - multiple_CD_num; notMultiple_num_A (A - 1) - multiple_CD_num (A - 1) A 1 multiple_CD_num if (notMultiple_num_A < 0) {
      notMultiple_num_A = 0;
    } notMultiple_num_A < 0 notMultiple_num_A 0 {
      notMultiple_num_A = 0;
    } notMultiple_num_A = 0 notMultiple_num_A 0 multiple_C_num = B / C multiple_C_num B / C B C multiple_D_num = B / D multiple_D_num B / D B D multiple_CD_num = multiple_C_num + multiple_D_num - (B / lcm(C, D)) multiple_CD_num multiple_C_num + multiple_D_num - (B / lcm(C, D)) multiple_C_num + multiple_D_num multiple_C_num multiple_D_num (B / lcm(C, D)) B lcm(C, D) lcm C D long notMultiple_num_B = B - multiple_CD_num; notMultiple_num_B B - multiple_CD_num B multiple_CD_num if (notMultiple_num_B < 0) {
      notMultiple_num_B = 0;
    } notMultiple_num_B < 0 notMultiple_num_B 0 {
      notMultiple_num_B = 0;
    } notMultiple_num_B = 0 notMultiple_num_B 0 System.out.println(notMultiple_num_B - notMultiple_num_A) System.out.println System.out System System.out notMultiple_num_B - notMultiple_num_A notMultiple_num_B notMultiple_num_A 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 static long lcm(long a, long b) {
    return (a * b) / gcd(a, b);
  } lcm {
    return (a * b) / gcd(a, b);
  } return (a * b) / gcd(a, b); (a * b) / gcd(a, b) (a * b) a b gcd(a, b) gcd a b long a a long b b public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    long A = scn.nextLong();
    long B = scn.nextLong();
    long C = scn.nextLong();
    long D = scn.nextLong();

    long multiple_C_num = (A - 1) / C;
    long multiple_D_num = (A - 1) / D;
    long multiple_CD_num = multiple_C_num + multiple_D_num - ((A - 1) / lcm(C, D));
    long notMultiple_num_A = (A - 1) - multiple_CD_num;
    if (notMultiple_num_A < 0) {
      notMultiple_num_A = 0;
    }

    multiple_C_num = B / C;
    multiple_D_num = B / D;
    multiple_CD_num = multiple_C_num + multiple_D_num - (B / lcm(C, D));
    long notMultiple_num_B = B - multiple_CD_num;
    if (notMultiple_num_B < 0) {
      notMultiple_num_B = 0;
    }

    System.out.println(notMultiple_num_B - notMultiple_num_A);

  }

  public static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);

  }

  public static long lcm(long a, long b) {
    return (a * b) / gcd(a, b);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    long A = scn.nextLong();
    long B = scn.nextLong();
    long C = scn.nextLong();
    long D = scn.nextLong();

    long multiple_C_num = (A - 1) / C;
    long multiple_D_num = (A - 1) / D;
    long multiple_CD_num = multiple_C_num + multiple_D_num - ((A - 1) / lcm(C, D));
    long notMultiple_num_A = (A - 1) - multiple_CD_num;
    if (notMultiple_num_A < 0) {
      notMultiple_num_A = 0;
    }

    multiple_C_num = B / C;
    multiple_D_num = B / D;
    multiple_CD_num = multiple_C_num + multiple_D_num - (B / lcm(C, D));
    long notMultiple_num_B = B - multiple_CD_num;
    if (notMultiple_num_B < 0) {
      notMultiple_num_B = 0;
    }

    System.out.println(notMultiple_num_B - notMultiple_num_A);

  }

  public static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);

  }

  public static long lcm(long a, long b) {
    return (a * b) / gcd(a, b);
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
    long A = scn.nextLong();
    long B = scn.nextLong();
    long C = scn.nextLong();
    long D = scn.nextLong();

    long multiple_C_num = (A - 1) / C;
    long multiple_D_num = (A - 1) / D;
    long multiple_CD_num = multiple_C_num + multiple_D_num - ((A - 1) / lcm(C, D));
    long notMultiple_num_A = (A - 1) - multiple_CD_num;
    if (notMultiple_num_A < 0) {
      notMultiple_num_A = 0;
    }

    multiple_C_num = B / C;
    multiple_D_num = B / D;
    multiple_CD_num = multiple_C_num + multiple_D_num - (B / lcm(C, D));
    long notMultiple_num_B = B - multiple_CD_num;
    if (notMultiple_num_B < 0) {
      notMultiple_num_B = 0;
    }

    System.out.println(notMultiple_num_B - notMultiple_num_A);

  }

  public static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);

  }

  public static long lcm(long a, long b) {
    return (a * b) / gcd(a, b);
  }
}