Problem p02995 (python)

Fixed submission:
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654

import math
import sys
import itertools
import queue
from functools import reduce
from fractions import gcd

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

mod = 1000000007

if __name__ == "__main__":
    A, B, C, D = map(int, sys.stdin.readline().split())
    A = A - 1
    c_div = int(B // C)
    d_div = int(B // D)
    cd_div = int(B // lcm(C, D))

    not_div1 = B - (c_div + d_div -cd_div)

    c_div = int(A // C)
    d_div = int(A // D)
    cd_div = int(A // lcm(C, D))

    not_div2 = A - (c_div + d_div -cd_div)

    print(not_div1 - not_div2)

Buggy submission (verdict: Runtime Error):
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654

import math
import sys
import itertools
import queue
from functools import reduce
from fractions import gcd

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

mod = 1000000007

"""
def gcd(a,b):
    """Compute the greatest common divisor of a and b"""
    while b > 0:
        a, b = b, a % b
    return a

def lcm(a, b):
    """Compute the lowest common multiple of a and b"""
    return a * b // gcd(a, b)
"""

if __name__ == "__main__":
    A, B, C, D = map(int, sys.stdin.readline().split())
    A = A - 1
    c_div = int(B // C)
    d_div = int(B // D)
    cd_div = int(B // lcm(C, D))

    not_div1 = B - (c_div + d_div -cd_div)

    c_div = int(A // C)
    d_div = int(A // D)
    cd_div = int(A // lcm(C, D))

    not_div2 = A - (c_div + d_div -cd_div)

    print(not_div1 - not_div2)

Buggy submission (verdict: Runtime Error):
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654

import math
import sys
import itertools
import queue

mod = 1000000007

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == "__main__":
    A, B, C, D = map(int, sys.stdin.readline().split())
    A = A - 1
    c_div = math.floor(B / C)
    #nc_div = (B - c_div)
    d_div = math.floor(B / D)
    #nd_div = (B - d_div)
    cd_div = math.floor(B / lcm(C, D))
    #ncd_div = (B - cd_div)
    #print(nc_div)
    #print(nd_div)
    #print(ncd_div)


    not_div1 = B - (c_div + d_div -cd_div)

    c_div = math.floor(A / C)
    nc_div = (A - c_div)
    d_div = math.floor(A / D)
    nd_div = (A - d_div)
    cd_div = math.floor(A / lcm(C, D))
    ncd_div = (A - cd_div)

    not_div2 = A - (c_div + d_div -cd_div)
    #not_div2 = nc_div + nd_div - ncd_div

    #print(not_div1)
    #print(not_div2)

    #print(not_div2)

    print(not_div1 - not_div2)