Buggy python submission (verdict: Runtime Error):
# 判定機にmathがインストールされていないため、
# gcd=最小公倍数、lcm=最少公約数(返り値整数)を実装
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    z = None
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        return z


def lcm(m, n):
    return (m * n) // gcd(m, n)


# input
A, B, C, D = map(int, input().split())

# check
AB = len(list(range(A, B + 1)))

C_cnt = B // C - (A - 1) // C
D_cnt = B // D - (A - 1) // C

lcm_CD = lcm(C, D)
lcm_cnt = B // lcm_CD - (A - 1) // lcm_CD

print(AB - C_cnt - D_cnt + lcm_cnt)

Fixed submission:
# 判定機にmathがインストールされていないため、
# gcd=最小公倍数、lcm=最少公約数(返り値整数)を実装
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    z = None
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        return z


def lcm(m, n):
    return (m * n) // gcd(m, n)


# input
A, B, C, D = map(int, input().split())

# check
AB = B - (A - 1)

C_cnt = B // C - (A - 1) // C
D_cnt = B // D - (A - 1) // D

lcm_CD = lcm(C, D)
lcm_cnt = B // lcm_CD - (A - 1) // lcm_CD

ans = AB - C_cnt - D_cnt + lcm_cnt

print(ans)

Buggy python submission (verdict: Runtime Error):
from math import gcd

# input
A, B, C, D = map(int, input().split())

# check
AB = len(list(range(A, B + 1)))

C_cnt = B // C - (A - 1) // C
D_cnt = B // D - (A - 1) // C

lcm_CD = C * D // gcd(C, D)
lcm_cnt = B // lcm_CD - (A - 1) // lcm_CD

print(AB - C_cnt - D_cnt + lcm_cnt)

Fixed submission:
# 判定機にmathがインストールされていないため、
# gcd=最小公倍数、lcm=最少公約数(返り値整数)を実装
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    z = None
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        return z


def lcm(m, n):
    return (m * n) // gcd(m, n)


# input
A, B, C, D = map(int, input().split())

# check
AB = B - (A - 1)

C_cnt = B // C - (A - 1) // C
D_cnt = B // D - (A - 1) // D

lcm_CD = lcm(C, D)
lcm_cnt = B // lcm_CD - (A - 1) // lcm_CD

ans = AB - C_cnt - D_cnt + lcm_cnt

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# input
A, B, C, D = map(int, input().split()) 

# check
ans = len([1 for i in range(A, B + 1) if i % C != 0 and i % D != 0])

print(ans)

Fixed submission:
# 判定機にmathがインストールされていないため、
# gcd=最小公倍数、lcm=最少公約数(返り値整数)を実装
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    z = None
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        return z


def lcm(m, n):
    return (m * n) // gcd(m, n)


# input
A, B, C, D = map(int, input().split())

# check
AB = B - (A - 1)

C_cnt = B // C - (A - 1) // C
D_cnt = B // D - (A - 1) // D

lcm_CD = lcm(C, D)
lcm_cnt = B // lcm_CD - (A - 1) // lcm_CD

ans = AB - C_cnt - D_cnt + lcm_cnt

print(ans)

Buggy python submission (verdict: Runtime Error):
# input
A, B, C, D = int(input())

# check
ans = len([1 for i in range(A, B + 1) if i % C != 0 and i % D != 0])

print(ans)


Fixed submission:
# 判定機にmathがインストールされていないため、
# gcd=最小公倍数、lcm=最少公約数(返り値整数)を実装
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    z = None
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        return z


def lcm(m, n):
    return (m * n) // gcd(m, n)


# input
A, B, C, D = map(int, input().split())

# check
AB = B - (A - 1)

C_cnt = B // C - (A - 1) // C
D_cnt = B // D - (A - 1) // D

lcm_CD = lcm(C, D)
lcm_cnt = B // lcm_CD - (A - 1) // lcm_CD

ans = AB - C_cnt - D_cnt + lcm_cnt

print(ans)