Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
input = sys.stdin.readline


def main():
    sc = Scan()
    a, b, c, d = sc.intarr()
    count = 0
    for i in range(a, b+1):
        if i % c != 0 and i % d != 0:
            count += 1
    print(count)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()


Fixed submission:
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    A, B, C, D = sc.intarr()
    div_b = B//C + B//D - B//(lcm(C, D))
    div_a = (A-1)//C + (A-1)//D - (A-1)//(lcm(C, D))

    ans = B - (A-1) - div_b + div_a

    print(ans)


def format_str(num):
    if num < 10:
        return "00" + str(num)
    elif num < 100:
        return "0" + str(num)
    else:
        return str(num)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):  # 最大公約数
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):  # 最小公倍数
    return a * b // gcd(a, b)


main()

Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
input = sys.stdin.readline


def main():
    sc = Scan()
    a, b, c, d = sc.intarr()
    count = 0
    for i in range(a, b+1):
        if i % c != 0 and i % d != 0:
            count += 1
    print(count)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()


Fixed submission:
import sys
import math
input = sys.stdin.readline


def main():
    sc = Scan()
    A, B, C, D = sc.intarr()
    div_b = B//C + B//D - B//(lcm(C, D))
    div_a = (A-1)//C + (A-1)//D - (A-1)//(lcm(C, D))

    ans = B - (A-1) - div_b + div_a

    print(ans)


def format_str(num):
    if num < 10:
        return "00" + str(num)
    elif num < 100:
        return "0" + str(num)
    else:
        return str(num)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def intarr_ver(self, n):
        return [int(input()) for _ in range(n)]

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


def display(array):
    for a in range(len(array)):
        if len(array) - a != 1:
            print(array[a], end=' ')
        else:
            print(array[a])


def gcd(a, b):  # 最大公約数
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):  # 最小公倍数
    return a * b // gcd(a, b)


main()