import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();
		a=a-1;
 
        long s1=a-(a/c+a/d-a/lcm(c,d));
        long s2=b-(b/c+b/d-b/lcm(c,d));
 
        System.out.println(s2-s1);
        sc.close();
    }
 
    static long gcd(long a,long b) {
        if(b%a==0) {
            return a;
        }
        return gcd(b%a,a);
    }
 
    static long lcm(long a,long b) {
        return a*b/gcd(a,b);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();
		a=a-1;
 
        long s1=a-(a/c+a/d-a/lcm(c,d));
        long s2=b-(b/c+b/d-b/lcm(c,d));
 
        System.out.println(s2-s1);
        sc.close();
    }
 
    static long gcd(long a,long b) {
        if(b%a==0) {
            return a;
        }
        return gcd(b%a,a);
    }
 
    static long lcm(long a,long b) {
        return a*b/gcd(a,b);
	}
} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();
		a=a-1;
 
        long s1=a-(a/c+a/d-a/lcm(c,d));
        long s2=b-(b/c+b/d-b/lcm(c,d));
 
        System.out.println(s2-s1);
        sc.close();
    } main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();
		a=a-1;
 
        long s1=a-(a/c+a/d-a/lcm(c,d));
        long s2=b-(b/c+b/d-b/lcm(c,d));
 
        System.out.println(s2-s1);
        sc.close();
    } 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 a=a-1 a a-1 a 1 long s1=a-(a/c+a/d-a/lcm(c,d)); s1 a-(a/c+a/d-a/lcm(c,d)) a (a/c+a/d-a/lcm(c,d)) a/c+a/d a/c a c a/d a d a/lcm(c,d) a lcm(c,d) lcm c d long s2=b-(b/c+b/d-b/lcm(c,d)); s2 b-(b/c+b/d-b/lcm(c,d)) b (b/c+b/d-b/lcm(c,d)) b/c+b/d b/c b c b/d b d b/lcm(c,d) b lcm(c,d) lcm c d System.out.println(s2-s1) System.out.println System.out System System.out s2-s1 s2 s1 sc.close() sc.close sc String[] args args static long gcd(long a,long b) {
        if(b%a==0) {
            return a;
        }
        return gcd(b%a,a);
    } gcd {
        if(b%a==0) {
            return a;
        }
        return gcd(b%a,a);
    } if(b%a==0) {
            return a;
        } b%a==0 b%a b a 0 {
            return a;
        } return a; a return gcd(b%a,a); gcd(b%a,a) gcd b%a b a a long a a long b b static long lcm(long a,long b) {
        return a*b/gcd(a,b);
	} lcm {
        return a*b/gcd(a,b);
	} 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 class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();
		a=a-1;
 
        long s1=a-(a/c+a/d-a/lcm(c,d));
        long s2=b-(b/c+b/d-b/lcm(c,d));
 
        System.out.println(s2-s1);
        sc.close();
    }
 
    static long gcd(long a,long b) {
        if(b%a==0) {
            return a;
        }
        return gcd(b%a,a);
    }
 
    static long lcm(long a,long b) {
        return a*b/gcd(a,b);
	}
} public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();
		a=a-1;
 
        long s1=a-(a/c+a/d-a/lcm(c,d));
        long s2=b-(b/c+b/d-b/lcm(c,d));
 
        System.out.println(s2-s1);
        sc.close();
    }
 
    static long gcd(long a,long b) {
        if(b%a==0) {
            return a;
        }
        return gcd(b%a,a);
    }
 
    static long lcm(long a,long b) {
        return a*b/gcd(a,b);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();
		a=a-1;
 
        long s1=a-(a/c+a/d-a/lcm(c,d));
        long s2=b-(b/c+b/d-b/lcm(c,d));
 
        System.out.println(s2-s1);
        sc.close();
    }
 
    static long gcd(long a,long b) {
        if(b%a==0) {
            return a;
        }
        return gcd(b%a,a);
    }
 
    static long lcm(long a,long b) {
        return a*b/gcd(a,b);
	}
}