Problem p02995 (python)

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
    
S = input().split()

A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

CD = (C * D) // gcd(C, D)

count_B = B - (B // C) - (B // D) + (B // CD)
count_A = A - 1 - ((A - 1) // C) - ((A - 1) // D) + ((A - 1) // CD)

print(count_B - count_A)

Buggy submission (verdict: Runtime Error):
import math

S = input().split()

A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

CD = (C * D) // math.gcd(C, D)

count_B = B - (B // C) - (B // D) + (B // CD)
count_A = A - 1 - ((A - 1) // C) - ((A - 1) // D) + ((A - 1) // CD)

print(count_B - count_A)

Buggy submission (verdict: Runtime Error):
import math

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

if __name__ == "__main__":
    S = input().split()

    A = int(S[0])
    B = int(S[1])
    C = int(S[2])
    D = int(S[3])

    CD = lcm(C, D)

    count_B = B - (B // C) - (B // D) + (B // CD)
    count_A = A - 1 - ((A - 1) // C) - ((A - 1) // D) + ((A - 1) // CD)

    print(count_B - count_A)

Buggy submission (verdict: Runtime Error):
import math

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

if __name__ == "__main__":
    S = input().split()

    A = int(S[0])
    B = int(S[1])
    C = int(S[2])
    D = int(S[3])

    CD = lcm(C, D)

    count_B = B - (B // C) - (B // D) + (B // CD)
    count_A = A - 1 - ((A - 1) // C) - ((A - 1) // D) + ((A - 1) // CD)

    print(count_B - count_A)

Buggy submission (verdict: Runtime Error):
import math

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

S = input().split()

A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

CD = lcm(C, D)

count_B = B - (B // C) - (B // D) + (B // CD)
count_A = A - 1 - ((A - 1) // C) - ((A - 1) // D) + ((A - 1) // CD)

print(count_B - count_A)

Buggy submission (verdict: Runtime Error):
S = input().split()

A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

count_U = B - A + 1

#count_C  = CountDivisibleNumber(C, A, B)
#print(count_C)
#count_D  = CountDivisibleNumber(D, A, B)
#print(count_D)
#count_CD = CountDivisibleNumber(lcm(C, D), A, B)
#print(count_CD)

count_C = (B // C) - (A // C)
count_D = (B // D) - (A // D)
CD = lcm(C, D)
count_CD = (B // CD) - (A // CD)

print(count_U - (count_C + count_D - count_CD))

Buggy submission (verdict: Runtime Error):
S = input().split()

A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

count_U = B - A + 1

#count_C  = CountDivisibleNumber(C, A, B)
#print(count_C)
#count_D  = CountDivisibleNumber(D, A, B)
#print(count_D)
#count_CD = CountDivisibleNumber(lcm(C, D), A, B)
#print(count_CD)

count_C = math.floor((B // C) - (A // C))
count_D = math.floor((B // D) - (A // D))
CD = lcm(C, D)
count_CD = math.floor((B // CD) - (A // CD))

print(count_U - (count_C + count_D - count_CD))

Buggy submission (verdict: Runtime Error):
import sys, math

def CountDivisibleNumber(divisor, min, max):
    i = 0
    count = 0
    residue = min % divisor
    if residue == 0:
        i = min
    else:
        if min < divisor:
            i = divisor
        else:
            i = min + (divisor - residue)
            #print(residue)
            #print(i)

    while i <= max:
        count += 1
        i += divisor
        #print(i)
    
    return count

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

S = input().split()

A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

count_U = B - A + 1

count_C  = CountDivisibleNumber(C, A, B)
#print(count_C)
count_D  = CountDivisibleNumber(D, A, B)
#print(count_D)
count_CD = CountDivisibleNumber(lcm(C, D), A, B)
#print(count_CD)

print(count_U - (count_C + count_D - count_CD))