# coding: utf-8

import re

import bisect

from datetime import datetime as dt

import bisect

import fractions



def gcd(a, b):

    return fractions.gcd(a, b)



def lcm(a, b):

    return a * b // gcd(a, b)



def calc(n, a, b):

    return n//a + n//b - n//lcm(a,b)



if __name__ == '__main__':

    a, b, c, d = list(map(int, input().split()))

    ## これで通った

    # num1 = b - calc(b,c,d)

    # num2 = (a-1) - calc(a-1, c,d)

    # print(num1-num2)



    ## これはとおらない

    ans = calc(b, c, d) - calc(a - 1, c, d)

    print((int(b - a + 1 - ans)))

# coding: utf-8

import re

import bisect

from datetime import datetime as dt

import bisect

import fractions



def gcd(a, b):

    return fractions.gcd(a, b)



def lcm(a, b):

    return a * b // gcd(a, b)



def calc(n, a, b):

    return int(n//a + n//b - n//lcm(a,b))



if __name__ == '__main__':

    a, b, c, d = list(map(int, input().split()))

    ans = calc(b, c, d) - calc(a - 1, c, d)

    print((b - a + 1 - ans))

# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import fractions


def gcd(a, b):
    return fractions.gcd(a, b)


def lcm(a, b):
    return a * b // gcd(a, b)


def calc(n, a, b):
    return n // a + n // b - n // lcm(a, b)


if __name__ == "__main__":
    a, b, c, d = list(map(int, input().split()))
    ## これで通った
    # num1 = b - calc(b,c,d)
    # num2 = (a-1) - calc(a-1, c,d)
    # print(num1-num2)
    ## これはとおらない
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print((int(b - a + 1 - ans)))

# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import fractions


def gcd(a, b):
    return fractions.gcd(a, b)


def lcm(a, b):
    return a * b // gcd(a, b)


def calc(n, a, b):
    return int(n // a + n // b - n // lcm(a, b))


if __name__ == "__main__":
    a, b, c, d = list(map(int, input().split()))
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print((b - a + 1 - ans))

-    return n // a + n // b - n // lcm(a, b) +    return int(n // a + n // b - n // lcm(a, b)) -    ## これで通った -    # num1 = b - calc(b,c,d) -    # num2 = (a-1) - calc(a-1, c,d) -    # print(num1-num2) -    ## これはとおらない -    print((int(b - a + 1 - ans))) +    print((b - a + 1 - ans))