import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long a = Long.parseLong(sc.next()) -1;
        long b = Long.parseLong(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        
        long a2 = a -(a/c) -(a/d) +(a / lcm(c, d));
        long b2 = b -(b/c) -(b/d) +(b / lcm(c, d));
        System.out.println(b2-a2);
    }
    
    private static long gcd(long a, long b){
        
        if(b == 0){
            return a;
        }else{
            return gcd(b, a % b);
        }
    }
    
    private static long lcm(long a, long b){
        
        return (a / gcd(a, b)) * b;
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long a = Long.parseLong(sc.next()) -1;
        long b = Long.parseLong(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        
        long a2 = a -(a/c) -(a/d) +(a / lcm(c, d));
        long b2 = b -(b/c) -(b/d) +(b / lcm(c, d));
        System.out.println(b2-a2);
    }
    
    private static long gcd(long a, long b){
        
        if(b == 0){
            return a;
        }else{
            return gcd(b, a % b);
        }
    }
    
    private static long lcm(long a, long b){
        
        return (a / gcd(a, b)) * b;
    }
} Main public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long a = Long.parseLong(sc.next()) -1;
        long b = Long.parseLong(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        
        long a2 = a -(a/c) -(a/d) +(a / lcm(c, d));
        long b2 = b -(b/c) -(b/d) +(b / lcm(c, d));
        System.out.println(b2-a2);
    } main {
        
        Scanner sc = new Scanner(System.in);
        
        long a = Long.parseLong(sc.next()) -1;
        long b = Long.parseLong(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        
        long a2 = a -(a/c) -(a/d) +(a / lcm(c, d));
        long b2 = b -(b/c) -(b/d) +(b / lcm(c, d));
        System.out.println(b2-a2);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = Long.parseLong(sc.next()) -1; a Long.parseLong(sc.next()) -1 Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc 1 long b = Long.parseLong(sc.next()); b Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc int c = Integer.parseInt(sc.next()); c Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int d = Integer.parseInt(sc.next()); d Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc long a2 = a -(a/c) -(a/d) +(a / lcm(c, d)); a2 a -(a/c) -(a/d) +(a / lcm(c, d)) a -(a/c) -(a/d) a -(a/c) -(a/d) a (a/c) a c (a/d) a d (a / lcm(c, d)) a lcm(c, d) lcm c d long b2 = b -(b/c) -(b/d) +(b / lcm(c, d)); b2 b -(b/c) -(b/d) +(b / lcm(c, d)) b -(b/c) -(b/d) b -(b/c) -(b/d) b (b/c) b c (b/d) b d (b / lcm(c, d)) b lcm(c, d) lcm c d System.out.println(b2-a2) System.out.println System.out System System.out b2-a2 b2 a2 String[] args args private static long gcd(long a, long b){
        
        if(b == 0){
            return a;
        }else{
            return gcd(b, a % b);
        }
    } gcd {
        
        if(b == 0){
            return a;
        }else{
            return gcd(b, a % b);
        }
    } if(b == 0){
            return a;
        }else{
            return gcd(b, a % b);
        } b == 0 b 0 {
            return a;
        } return a; a {
            return gcd(b, a % b);
        } return gcd(b, a % b); gcd(b, a % b) gcd b a % b a b long a a long b b private static long lcm(long a, long b){
        
        return (a / gcd(a, b)) * b;
    } lcm {
        
        return (a / gcd(a, b)) * b;
    } return (a / gcd(a, b)) * b; (a / gcd(a, b)) * b (a / gcd(a, b)) a gcd(a, b) gcd a b b long a a long b b public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long a = Long.parseLong(sc.next()) -1;
        long b = Long.parseLong(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        
        long a2 = a -(a/c) -(a/d) +(a / lcm(c, d));
        long b2 = b -(b/c) -(b/d) +(b / lcm(c, d));
        System.out.println(b2-a2);
    }
    
    private static long gcd(long a, long b){
        
        if(b == 0){
            return a;
        }else{
            return gcd(b, a % b);
        }
    }
    
    private static long lcm(long a, long b){
        
        return (a / gcd(a, b)) * b;
    }
} public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long a = Long.parseLong(sc.next()) -1;
        long b = Long.parseLong(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        
        long a2 = a -(a/c) -(a/d) +(a / lcm(c, d));
        long b2 = b -(b/c) -(b/d) +(b / lcm(c, d));
        System.out.println(b2-a2);
    }
    
    private static long gcd(long a, long b){
        
        if(b == 0){
            return a;
        }else{
            return gcd(b, a % b);
        }
    }
    
    private static long lcm(long a, long b){
        
        return (a / gcd(a, b)) * b;
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long a = Long.parseLong(sc.next()) -1;
        long b = Long.parseLong(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        
        long a2 = a -(a/c) -(a/d) +(a / lcm(c, d));
        long b2 = b -(b/c) -(b/d) +(b / lcm(c, d));
        System.out.println(b2-a2);
    }
    
    private static long gcd(long a, long b){
        
        if(b == 0){
            return a;
        }else{
            return gcd(b, a % b);
        }
    }
    
    private static long lcm(long a, long b){
        
        return (a / gcd(a, b)) * b;
    }
}