
import java.util.Scanner;
import java.util.stream.LongStream;

public class Main {
    public static Long gcd(Long a, Long b) {
        if (a < b) return gcd(b, a);
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static Long lcm(Long a, Long b) {
        if (a < b) return lcm(b, a);
        return a * b / gcd(a, b);
    }

    public static Long cal(Long a, Long b) {
        Long min_f;
        if(a%b == 0) {
            min_f = a / b;
        } else {
            min_f= (a / b) + 1;
        }
        return min_f;

    }
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Long a = scanner.nextLong();
        Long b = scanner.nextLong();
        Long c = scanner.nextLong();
        Long d = scanner.nextLong();

        Long a_b_min = cal(a,c);
        Long a_b_max = b / c;
        Long total1 = (a_b_max - a_b_min) + 1;

        Long a_d_min = cal(a,d);
        Long b_d_max = b / d;
        Long total2 = (b_d_max - a_d_min) + 1;

        Long lcm = lcm(c,d);
        Long lcm_min = cal(a,lcm);
        Long lcm_max = b / lcm;
        Long total3 = (lcm_max - lcm_min) + 1;

        System.out.println((b-a+1) - (total1+total2-total3));


    }
} import java.util.Scanner; Scanner java.util import java.util.stream.LongStream; LongStream java.util.stream public class Main {
    public static Long gcd(Long a, Long b) {
        if (a < b) return gcd(b, a);
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static Long lcm(Long a, Long b) {
        if (a < b) return lcm(b, a);
        return a * b / gcd(a, b);
    }

    public static Long cal(Long a, Long b) {
        Long min_f;
        if(a%b == 0) {
            min_f = a / b;
        } else {
            min_f= (a / b) + 1;
        }
        return min_f;

    }
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Long a = scanner.nextLong();
        Long b = scanner.nextLong();
        Long c = scanner.nextLong();
        Long d = scanner.nextLong();

        Long a_b_min = cal(a,c);
        Long a_b_max = b / c;
        Long total1 = (a_b_max - a_b_min) + 1;

        Long a_d_min = cal(a,d);
        Long b_d_max = b / d;
        Long total2 = (b_d_max - a_d_min) + 1;

        Long lcm = lcm(c,d);
        Long lcm_min = cal(a,lcm);
        Long lcm_max = b / lcm;
        Long total3 = (lcm_max - lcm_min) + 1;

        System.out.println((b-a+1) - (total1+total2-total3));


    }
} Main public static Long gcd(Long a, Long b) {
        if (a < b) return gcd(b, a);
        if (b == 0) return a;
        return gcd(b, a % b);
    } gcd {
        if (a < b) return gcd(b, a);
        if (b == 0) return a;
        return gcd(b, a % b);
    } if (a < b) return gcd(b, a); a < b a b return gcd(b, a); gcd(b, a) gcd b a if (b == 0) return a; b == 0 b 0 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) {
        if (a < b) return lcm(b, a);
        return a * b / gcd(a, b);
    } lcm {
        if (a < b) return lcm(b, a);
        return a * b / gcd(a, b);
    } if (a < b) return lcm(b, a); a < b a b return lcm(b, a); lcm(b, a) lcm b a 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 static Long cal(Long a, Long b) {
        Long min_f;
        if(a%b == 0) {
            min_f = a / b;
        } else {
            min_f= (a / b) + 1;
        }
        return min_f;

    } cal {
        Long min_f;
        if(a%b == 0) {
            min_f = a / b;
        } else {
            min_f= (a / b) + 1;
        }
        return min_f;

    } Long min_f; min_f if(a%b == 0) {
            min_f = a / b;
        } else {
            min_f= (a / b) + 1;
        } a%b == 0 a%b a b 0 {
            min_f = a / b;
        } min_f = a / b min_f a / b a b {
            min_f= (a / b) + 1;
        } min_f= (a / b) + 1 min_f (a / b) + 1 (a / b) a b 1 return min_f; min_f Long a a Long b b public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Long a = scanner.nextLong();
        Long b = scanner.nextLong();
        Long c = scanner.nextLong();
        Long d = scanner.nextLong();

        Long a_b_min = cal(a,c);
        Long a_b_max = b / c;
        Long total1 = (a_b_max - a_b_min) + 1;

        Long a_d_min = cal(a,d);
        Long b_d_max = b / d;
        Long total2 = (b_d_max - a_d_min) + 1;

        Long lcm = lcm(c,d);
        Long lcm_min = cal(a,lcm);
        Long lcm_max = b / lcm;
        Long total3 = (lcm_max - lcm_min) + 1;

        System.out.println((b-a+1) - (total1+total2-total3));


    } main {
        //コード
        Scanner scanner = new Scanner(System.in);
        Long a = scanner.nextLong();
        Long b = scanner.nextLong();
        Long c = scanner.nextLong();
        Long d = scanner.nextLong();

        Long a_b_min = cal(a,c);
        Long a_b_max = b / c;
        Long total1 = (a_b_max - a_b_min) + 1;

        Long a_d_min = cal(a,d);
        Long b_d_max = b / d;
        Long total2 = (b_d_max - a_d_min) + 1;

        Long lcm = lcm(c,d);
        Long lcm_min = cal(a,lcm);
        Long lcm_max = b / lcm;
        Long total3 = (lcm_max - lcm_min) + 1;

        System.out.println((b-a+1) - (total1+total2-total3));


    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) Long a = scanner.nextLong(); a scanner.nextLong() scanner.nextLong scanner Long b = scanner.nextLong(); b scanner.nextLong() scanner.nextLong scanner Long c = scanner.nextLong(); c scanner.nextLong() scanner.nextLong scanner Long d = scanner.nextLong(); d scanner.nextLong() scanner.nextLong scanner Long a_b_min = cal(a,c); a_b_min cal(a,c) cal a c Long a_b_max = b / c; a_b_max b / c b c Long total1 = (a_b_max - a_b_min) + 1; total1 (a_b_max - a_b_min) + 1 (a_b_max - a_b_min) a_b_max a_b_min 1 Long a_d_min = cal(a,d); a_d_min cal(a,d) cal a d Long b_d_max = b / d; b_d_max b / d b d Long total2 = (b_d_max - a_d_min) + 1; total2 (b_d_max - a_d_min) + 1 (b_d_max - a_d_min) b_d_max a_d_min 1 Long lcm = lcm(c,d); lcm lcm(c,d) lcm c d Long lcm_min = cal(a,lcm); lcm_min cal(a,lcm) cal a lcm Long lcm_max = b / lcm; lcm_max b / lcm b lcm Long total3 = (lcm_max - lcm_min) + 1; total3 (lcm_max - lcm_min) + 1 (lcm_max - lcm_min) lcm_max lcm_min 1 System.out.println((b-a+1) - (total1+total2-total3)) System.out.println System.out System System.out (b-a+1) - (total1+total2-total3) (b-a+1) b-a b a 1 (total1+total2-total3) total1+total2 total1 total2 total3 String[] args args public class Main {
    public static Long gcd(Long a, Long b) {
        if (a < b) return gcd(b, a);
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static Long lcm(Long a, Long b) {
        if (a < b) return lcm(b, a);
        return a * b / gcd(a, b);
    }

    public static Long cal(Long a, Long b) {
        Long min_f;
        if(a%b == 0) {
            min_f = a / b;
        } else {
            min_f= (a / b) + 1;
        }
        return min_f;

    }
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Long a = scanner.nextLong();
        Long b = scanner.nextLong();
        Long c = scanner.nextLong();
        Long d = scanner.nextLong();

        Long a_b_min = cal(a,c);
        Long a_b_max = b / c;
        Long total1 = (a_b_max - a_b_min) + 1;

        Long a_d_min = cal(a,d);
        Long b_d_max = b / d;
        Long total2 = (b_d_max - a_d_min) + 1;

        Long lcm = lcm(c,d);
        Long lcm_min = cal(a,lcm);
        Long lcm_max = b / lcm;
        Long total3 = (lcm_max - lcm_min) + 1;

        System.out.println((b-a+1) - (total1+total2-total3));


    }
} public class Main {
    public static Long gcd(Long a, Long b) {
        if (a < b) return gcd(b, a);
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static Long lcm(Long a, Long b) {
        if (a < b) return lcm(b, a);
        return a * b / gcd(a, b);
    }

    public static Long cal(Long a, Long b) {
        Long min_f;
        if(a%b == 0) {
            min_f = a / b;
        } else {
            min_f= (a / b) + 1;
        }
        return min_f;

    }
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Long a = scanner.nextLong();
        Long b = scanner.nextLong();
        Long c = scanner.nextLong();
        Long d = scanner.nextLong();

        Long a_b_min = cal(a,c);
        Long a_b_max = b / c;
        Long total1 = (a_b_max - a_b_min) + 1;

        Long a_d_min = cal(a,d);
        Long b_d_max = b / d;
        Long total2 = (b_d_max - a_d_min) + 1;

        Long lcm = lcm(c,d);
        Long lcm_min = cal(a,lcm);
        Long lcm_max = b / lcm;
        Long total3 = (lcm_max - lcm_min) + 1;

        System.out.println((b-a+1) - (total1+total2-total3));


    }
} Main

import java.util.Scanner;
import java.util.stream.LongStream;

public class Main {
    public static Long gcd(Long a, Long b) {
        if (a < b) return gcd(b, a);
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static Long lcm(Long a, Long b) {
        if (a < b) return lcm(b, a);
        return a * b / gcd(a, b);
    }

    public static Long cal(Long a, Long b) {
        Long min_f;
        if(a%b == 0) {
            min_f = a / b;
        } else {
            min_f= (a / b) + 1;
        }
        return min_f;

    }
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Long a = scanner.nextLong();
        Long b = scanner.nextLong();
        Long c = scanner.nextLong();
        Long d = scanner.nextLong();

        Long a_b_min = cal(a,c);
        Long a_b_max = b / c;
        Long total1 = (a_b_max - a_b_min) + 1;

        Long a_d_min = cal(a,d);
        Long b_d_max = b / d;
        Long total2 = (b_d_max - a_d_min) + 1;

        Long lcm = lcm(c,d);
        Long lcm_min = cal(a,lcm);
        Long lcm_max = b / lcm;
        Long total3 = (lcm_max - lcm_min) + 1;

        System.out.println((b-a+1) - (total1+total2-total3));


    }
}
