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 cdDt = b/lcm(c,d);
        long cDt = b/c;
        long dDt = b/d;
        long ansT = b-cDt-dDt+cdDt;
        long cdDa = (a-1)/lcm(c,d);
        long cDa = (a-1)/c;
        long dDa = (a-1)/d;
        long ansA = a-1-cDa-dDa+cdDa;
        System.out.println(ansT-ansA);
    }
    static long gcd(long x,long y){
        if (y==0)return x;
        else return gcd(y,x%y);
    }
    static long lcm(long x,long y){
        return x/gcd(x,y)*y;
    }
} 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 cdDt = b/lcm(c,d);
        long cDt = b/c;
        long dDt = b/d;
        long ansT = b-cDt-dDt+cdDt;
        long cdDa = (a-1)/lcm(c,d);
        long cDa = (a-1)/c;
        long dDa = (a-1)/d;
        long ansA = a-1-cDa-dDa+cdDa;
        System.out.println(ansT-ansA);
    }
    static long gcd(long x,long y){
        if (y==0)return x;
        else return gcd(y,x%y);
    }
    static long lcm(long x,long y){
        return x/gcd(x,y)*y;
    }
} 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 cdDt = b/lcm(c,d);
        long cDt = b/c;
        long dDt = b/d;
        long ansT = b-cDt-dDt+cdDt;
        long cdDa = (a-1)/lcm(c,d);
        long cDa = (a-1)/c;
        long dDa = (a-1)/d;
        long ansA = a-1-cDa-dDa+cdDa;
        System.out.println(ansT-ansA);
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        long cdDt = b/lcm(c,d);
        long cDt = b/c;
        long dDt = b/d;
        long ansT = b-cDt-dDt+cdDt;
        long cdDa = (a-1)/lcm(c,d);
        long cDa = (a-1)/c;
        long dDa = (a-1)/d;
        long ansA = a-1-cDa-dDa+cdDa;
        System.out.println(ansT-ansA);
    } 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 cdDt = b/lcm(c,d); cdDt b/lcm(c,d) b lcm(c,d) lcm c d long cDt = b/c; cDt b/c b c long dDt = b/d; dDt b/d b d long ansT = b-cDt-dDt+cdDt; ansT b-cDt-dDt+cdDt b-cDt-dDt b-cDt-dDt b cDt dDt cdDt long cdDa = (a-1)/lcm(c,d); cdDa (a-1)/lcm(c,d) (a-1) a 1 lcm(c,d) lcm c d long cDa = (a-1)/c; cDa (a-1)/c (a-1) a 1 c long dDa = (a-1)/d; dDa (a-1)/d (a-1) a 1 d long ansA = a-1-cDa-dDa+cdDa; ansA a-1-cDa-dDa+cdDa a-1-cDa-dDa cDa a-1-cDa-dDa a 1 cDa dDa cdDa System.out.println(ansT-ansA) System.out.println System.out System System.out ansT-ansA ansT ansA String[] args args static long gcd(long x,long y){
        if (y==0)return x;
        else return gcd(y,x%y);
    } gcd {
        if (y==0)return x;
        else return gcd(y,x%y);
    } if (y==0)return x;
        else return gcd(y,x%y); y==0 y 0 return x; x return gcd(y,x%y); gcd(y,x%y) gcd y x%y x y long x x long y y static long lcm(long x,long y){
        return x/gcd(x,y)*y;
    } lcm {
        return x/gcd(x,y)*y;
    } return x/gcd(x,y)*y; x/gcd(x,y)*y x/gcd(x,y) x gcd(x,y) gcd x y y long x x long y y 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 cdDt = b/lcm(c,d);
        long cDt = b/c;
        long dDt = b/d;
        long ansT = b-cDt-dDt+cdDt;
        long cdDa = (a-1)/lcm(c,d);
        long cDa = (a-1)/c;
        long dDa = (a-1)/d;
        long ansA = a-1-cDa-dDa+cdDa;
        System.out.println(ansT-ansA);
    }
    static long gcd(long x,long y){
        if (y==0)return x;
        else return gcd(y,x%y);
    }
    static long lcm(long x,long y){
        return x/gcd(x,y)*y;
    }
} 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 cdDt = b/lcm(c,d);
        long cDt = b/c;
        long dDt = b/d;
        long ansT = b-cDt-dDt+cdDt;
        long cdDa = (a-1)/lcm(c,d);
        long cDa = (a-1)/c;
        long dDa = (a-1)/d;
        long ansA = a-1-cDa-dDa+cdDa;
        System.out.println(ansT-ansA);
    }
    static long gcd(long x,long y){
        if (y==0)return x;
        else return gcd(y,x%y);
    }
    static long lcm(long x,long y){
        return x/gcd(x,y)*y;
    }
} 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 cdDt = b/lcm(c,d);
        long cDt = b/c;
        long dDt = b/d;
        long ansT = b-cDt-dDt+cdDt;
        long cdDa = (a-1)/lcm(c,d);
        long cDa = (a-1)/c;
        long dDa = (a-1)/d;
        long ansA = a-1-cDa-dDa+cdDa;
        System.out.println(ansT-ansA);
    }
    static long gcd(long x,long y){
        if (y==0)return x;
        else return gcd(y,x%y);
    }
    static long lcm(long x,long y){
        return x/gcd(x,y)*y;
    }
}
