import java.util.*;
public class Main{
  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 E =(A-1)/C;long F =B/C;
    long G =(A-1)/D;long H =B/D;
    long I =C*D;
    long s =C%D;
    while(s!=0){
      s=C%D;
      C=D;
      D=s;}
    long J =I/C;
    long K =(A-1)/J;long L =B/J;
    long ans =B-A+1-F+E+G-H+L-K;
    System.out.println(ans);
  }
} import java.util.*; util.* java public class Main{
  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 E =(A-1)/C;long F =B/C;
    long G =(A-1)/D;long H =B/D;
    long I =C*D;
    long s =C%D;
    while(s!=0){
      s=C%D;
      C=D;
      D=s;}
    long J =I/C;
    long K =(A-1)/J;long L =B/J;
    long ans =B-A+1-F+E+G-H+L-K;
    System.out.println(ans);
  }
} Main 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 E =(A-1)/C;long F =B/C;
    long G =(A-1)/D;long H =B/D;
    long I =C*D;
    long s =C%D;
    while(s!=0){
      s=C%D;
      C=D;
      D=s;}
    long J =I/C;
    long K =(A-1)/J;long L =B/J;
    long ans =B-A+1-F+E+G-H+L-K;
    System.out.println(ans);
  } main {
    Scanner sc =new Scanner(System.in);
    long A = sc.nextLong();
    long B =sc.nextLong();
    long C =sc.nextLong();
    long D =sc.nextLong();
    long E =(A-1)/C;long F =B/C;
    long G =(A-1)/D;long H =B/D;
    long I =C*D;
    long s =C%D;
    while(s!=0){
      s=C%D;
      C=D;
      D=s;}
    long J =I/C;
    long K =(A-1)/J;long L =B/J;
    long ans =B-A+1-F+E+G-H+L-K;
    System.out.println(ans);
  } 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 E =(A-1)/C; E (A-1)/C (A-1) A 1 C long F =B/C; F B/C B C long G =(A-1)/D; G (A-1)/D (A-1) A 1 D long H =B/D; H B/D B D long I =C*D; I C*D C D long s =C%D; s C%D C D while(s!=0){
      s=C%D;
      C=D;
      D=s;} s!=0 s 0 {
      s=C%D;
      C=D;
      D=s;} s=C%D s C%D C D C=D C D D=s D s long J =I/C; J I/C I C long K =(A-1)/J; K (A-1)/J (A-1) A 1 J long L =B/J; L B/J B J long ans =B-A+1-F+E+G-H+L-K; ans B-A+1-F+E+G-H+L-K B-A+1-F+E+G-H+L B-A+1-F+E+G-H B-A+1-F+E+G B-A+1-F+E+G B-A+1-F B-A+1 B-A B A 1 F E G H L K System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main{
  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 E =(A-1)/C;long F =B/C;
    long G =(A-1)/D;long H =B/D;
    long I =C*D;
    long s =C%D;
    while(s!=0){
      s=C%D;
      C=D;
      D=s;}
    long J =I/C;
    long K =(A-1)/J;long L =B/J;
    long ans =B-A+1-F+E+G-H+L-K;
    System.out.println(ans);
  }
} public class Main{
  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 E =(A-1)/C;long F =B/C;
    long G =(A-1)/D;long H =B/D;
    long I =C*D;
    long s =C%D;
    while(s!=0){
      s=C%D;
      C=D;
      D=s;}
    long J =I/C;
    long K =(A-1)/J;long L =B/J;
    long ans =B-A+1-F+E+G-H+L-K;
    System.out.println(ans);
  }
} Main
import java.util.*;
public class Main{
  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 E =(A-1)/C;long F =B/C;
    long G =(A-1)/D;long H =B/D;
    long I =C*D;
    long s =C%D;
    while(s!=0){
      s=C%D;
      C=D;
      D=s;}
    long J =I/C;
    long K =(A-1)/J;long L =B/J;
    long ans =B-A+1-F+E+G-H+L-K;
    System.out.println(ans);
  }
}