Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
import numpy as np
import math
A, B, C, D = [int(i) for i in input().split()]

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

large = np.max([C, D])
small = np.min([C, D])

#def gcd(a, b):
#    while b:
#        a, b = b, a % b
#    return a

while small != 0:
    large, small = small, large % small
    print(large, small)
gcd = large

large = np.max([C, D])
small = np.min([C, D])


num_B_1 = B // C
num_B_2 = B // D
num_B_3 = B // lcm(large, small, gcd)

num_A_1 = (A-1) // C
num_A_2 = (A-1) // D
num_A_3 = (A-1) // lcm(large, small, gcd)

numB = num_B_1 + num_B_2 - num_B_3
numA = num_A_1 + num_A_2 - num_A_3

print((B-A+1) - (numB - numA))

import numpy as np
import math
A, B, C, D = [int(i) for i in input().split()]

large = np.max([C, D])
small = np.min([C, D])
quo = large // small
rem = large % small
g = small
while rem != 0:
    large = small 
    small = rem
    quo = large // small
    rem = large % small

g = small
#print(g)

l = C / g * D

#num_B_1 = math.floor(B / C)
#num_B_2 = math.floor(B / D)
#num_B_3 = math.floor(B / l)
num_B_1 = B // C
num_B_2 = B // D
num_B_3 = B // l
num_B = B - (num_B_1 + num_B_2 - num_B_3)

#num_A_1 = math.floor((A - 1) / C)
#num_A_2 = math.floor((A - 1) / D)
#num_A_3 = math.floor((A - 1) / l)
num_A_1 = (A - 1) // C
num_A_2 = (A - 1) // D
num_A_3 = (A - 1) // l
num_A = (A - 1) - (num_A_1 + num_A_2 - num_A_3)

print(num_B - num_A)

import numpy as np
import math
A, B, C, D = [int(i) for i in input().split()]
 
large = np.max([C, D])
small = np.min([C, D])
 
def gcd(a, b):
    while b:
        a, b = b, a % b
    print(a)
    return a
 
def lcm(a, b):
    return a * b // gcd (a, b)
 
num_B_1 = B // C
num_B_2 = B // D
num_B_3 = B // lcm(large, small)
 
num_A_1 = (A-1) // C
num_A_2 = (A-1) // D
num_A_3 = (A-1) // lcm(large, small)
 
numB = num_B_1 + num_B_2 - num_B_3
numA = num_A_1 + num_A_2 - num_A_3
 
print((B-A+1) - (numB - numA))


import numpy as np
import math
A, B, C, D = [int(i) for i in input().split()]

large = np.max([C, D])
small = np.min([C, D])
quo = large // small
rem = large % small
g = small
while rem != 0:
    large = small 
    small = rem
    quo = large // small
    rem = large % small

g = small
#print(g)

l = C / g * D

#num_B_1 = math.floor(B / C)
#num_B_2 = math.floor(B / D)
#num_B_3 = math.floor(B / l)
num_B_1 = B // C
num_B_2 = B // D
num_B_3 = B // l
num_B = B - (num_B_1 + num_B_2 - num_B_3)

#num_A_1 = math.floor((A - 1) / C)
#num_A_2 = math.floor((A - 1) / D)
#num_A_3 = math.floor((A - 1) / l)
num_A_1 = (A - 1) // C
num_A_2 = (A - 1) // D
num_A_3 = ((A - 1) // l
num_A = (A - 1) - (num_A_1 + num_A_2 - num_A_3)

print(num_B - num_A)

import numpy as np
A, B, C, D = [int(i) for i in input().split()]

large = np.max([C, D])
small = np.min([C, D])

g = large
while small != 0:
    large, small = small, large % small

g = large

l = C * D // g

num_B_1 = B // C
num_B_2 = B // D
num_B_3 = B // l
num_B = B - (num_B_1 + num_B_2 - num_B_3)

num_A_1 = (A - 1) // C
num_A_2 = (A - 1) // D
num_A_3 = (A - 1) // l
num_A = (A - 1) - (num_A_1 + num_A_2 - num_A_3)

print(num_B - num_A)


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted