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 BC =B/C;
    Long BD =B/D;
    Long BCD = B/(C*D/syori(C,D));
    Long B_ans = B + BCD - BC - BD;

    Long AC =(A-1)/C;
    Long AD =(A-1)/D;
    Long ACD = (A-1)/(C*D/syori(C,D));
    Long A_ans = A -1 + ACD - AC - AD;
    System.out.println(B_ans - A_ans);
  
  }

  public static Long syori(Long C, Long D){
    if(C>=D){
      if(C%D==0){ 
        return D;
      }else{
        return syori(D,C%D);
      }
    }else{
      if(D%C==0){ 
        return C;
      }else{
        return syori(C,D%C);
      }
    }
  }

  
}
 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 BC =B/C;
    Long BD =B/D;
    Long BCD = B/(C*D/syori(C,D));
    Long B_ans = B + BCD - BC - BD;

    Long AC =(A-1)/C;
    Long AD =(A-1)/D;
    Long ACD = (A-1)/(C*D/syori(C,D));
    Long A_ans = A -1 + ACD - AC - AD;
    System.out.println(B_ans - A_ans);
  
  }

  public static Long syori(Long C, Long D){
    if(C>=D){
      if(C%D==0){ 
        return D;
      }else{
        return syori(D,C%D);
      }
    }else{
      if(D%C==0){ 
        return C;
      }else{
        return syori(C,D%C);
      }
    }
  }

  
} 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 BC =B/C;
    Long BD =B/D;
    Long BCD = B/(C*D/syori(C,D));
    Long B_ans = B + BCD - BC - BD;

    Long AC =(A-1)/C;
    Long AD =(A-1)/D;
    Long ACD = (A-1)/(C*D/syori(C,D));
    Long A_ans = A -1 + ACD - AC - AD;
    System.out.println(B_ans - A_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 BC =B/C;
    Long BD =B/D;
    Long BCD = B/(C*D/syori(C,D));
    Long B_ans = B + BCD - BC - BD;

    Long AC =(A-1)/C;
    Long AD =(A-1)/D;
    Long ACD = (A-1)/(C*D/syori(C,D));
    Long A_ans = A -1 + ACD - AC - AD;
    System.out.println(B_ans - A_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 BC =B/C; BC B/C B C Long BD =B/D; BD B/D B D Long BCD = B/(C*D/syori(C,D)); BCD B/(C*D/syori(C,D)) B (C*D/syori(C,D)) C*D C D syori(C,D) syori C D Long B_ans = B + BCD - BC - BD; B_ans B + BCD - BC - BD B + BCD - BC - BD B + BCD B BCD BC BD Long AC =(A-1)/C; AC (A-1)/C (A-1) A 1 C Long AD =(A-1)/D; AD (A-1)/D (A-1) A 1 D Long ACD = (A-1)/(C*D/syori(C,D)); ACD (A-1)/(C*D/syori(C,D)) (A-1) A 1 (C*D/syori(C,D)) C*D C D syori(C,D) syori C D Long A_ans = A -1 + ACD - AC - AD; A_ans A -1 + ACD - AC - AD A -1 + ACD - AC - AD A -1 + ACD A -1 A 1 ACD AC AD System.out.println(B_ans - A_ans) System.out.println System.out System System.out B_ans - A_ans B_ans A_ans String[] args args public static Long syori(Long C, Long D){
    if(C>=D){
      if(C%D==0){ 
        return D;
      }else{
        return syori(D,C%D);
      }
    }else{
      if(D%C==0){ 
        return C;
      }else{
        return syori(C,D%C);
      }
    }
  } syori {
    if(C>=D){
      if(C%D==0){ 
        return D;
      }else{
        return syori(D,C%D);
      }
    }else{
      if(D%C==0){ 
        return C;
      }else{
        return syori(C,D%C);
      }
    }
  } if(C>=D){
      if(C%D==0){ 
        return D;
      }else{
        return syori(D,C%D);
      }
    }else{
      if(D%C==0){ 
        return C;
      }else{
        return syori(C,D%C);
      }
    } C>=D C D {
      if(C%D==0){ 
        return D;
      }else{
        return syori(D,C%D);
      }
    } if(C%D==0){ 
        return D;
      }else{
        return syori(D,C%D);
      } C%D==0 C%D C D 0 { 
        return D;
      } return D; D {
        return syori(D,C%D);
      } return syori(D,C%D); syori(D,C%D) syori D C%D C D {
      if(D%C==0){ 
        return C;
      }else{
        return syori(C,D%C);
      }
    } if(D%C==0){ 
        return C;
      }else{
        return syori(C,D%C);
      } D%C==0 D%C D C 0 { 
        return C;
      } return C; C {
        return syori(C,D%C);
      } return syori(C,D%C); syori(C,D%C) syori C D%C D C Long C C Long D D 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 BC =B/C;
    Long BD =B/D;
    Long BCD = B/(C*D/syori(C,D));
    Long B_ans = B + BCD - BC - BD;

    Long AC =(A-1)/C;
    Long AD =(A-1)/D;
    Long ACD = (A-1)/(C*D/syori(C,D));
    Long A_ans = A -1 + ACD - AC - AD;
    System.out.println(B_ans - A_ans);
  
  }

  public static Long syori(Long C, Long D){
    if(C>=D){
      if(C%D==0){ 
        return D;
      }else{
        return syori(D,C%D);
      }
    }else{
      if(D%C==0){ 
        return C;
      }else{
        return syori(C,D%C);
      }
    }
  }

  
} 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 BC =B/C;
    Long BD =B/D;
    Long BCD = B/(C*D/syori(C,D));
    Long B_ans = B + BCD - BC - BD;

    Long AC =(A-1)/C;
    Long AD =(A-1)/D;
    Long ACD = (A-1)/(C*D/syori(C,D));
    Long A_ans = A -1 + ACD - AC - AD;
    System.out.println(B_ans - A_ans);
  
  }

  public static Long syori(Long C, Long D){
    if(C>=D){
      if(C%D==0){ 
        return D;
      }else{
        return syori(D,C%D);
      }
    }else{
      if(D%C==0){ 
        return C;
      }else{
        return syori(C,D%C);
      }
    }
  }

  
} 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 BC =B/C;
    Long BD =B/D;
    Long BCD = B/(C*D/syori(C,D));
    Long B_ans = B + BCD - BC - BD;

    Long AC =(A-1)/C;
    Long AD =(A-1)/D;
    Long ACD = (A-1)/(C*D/syori(C,D));
    Long A_ans = A -1 + ACD - AC - AD;
    System.out.println(B_ans - A_ans);
  
  }

  public static Long syori(Long C, Long D){
    if(C>=D){
      if(C%D==0){ 
        return D;
      }else{
        return syori(D,C%D);
      }
    }else{
      if(D%C==0){ 
        return C;
      }else{
        return syori(C,D%C);
      }
    }
  }

  
}

