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 sys
 import copy
 
 sys.setrecursionlimit(1000000)
 
 
 # input = sys.stdin.readline
 
 
 
 def GCD(x, y):
     return x if y == 0 else GCD(y, x % y)
 
 
 def LCM(x, y):
     return x // GCD(x, y) * y
 
 
 A, B, C, D = map(int, input().split())
 
 S = B - A + 1
 
 canC = B // C - (A - 1) // C
 canD = B // D - (A - 1) // D
 canCD = B // LCM(C, D) - (A - 1) // LCM(C, D)
 
 print(S - (canC + canD) + canCD)

import math
import copy
import fractions
import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

num = getInputListInt()

a = num[0]
b = num[1]
c = num[2]
d = num[3]

c_modzero = math.floor(b/c) - math.floor((a-1)/c)
d_modzero = math.floor(b/d) - math.floor((a-1)/d)

cd = c / fractions.gcd(c, d) *d

cd_modzero = math.floor(b/cd) - math.floor((a-1)/cd)

ans = b - a + 1 - (c_modzero + d_modzero - cd_modzero)

print(int(ans))

import math
import copy
from fractions import gcd
# import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

num = getInputListInt()

a = num[0]
b = num[1]
c = num[2]
d = num[3]

c_modzero = math.floor(b/c) - math.floor((a-1)/c)
d_modzero = math.floor(b/d) - math.floor((a-1)/d)

cd = math.floor(c*d/ gcd(c, d))

cd_modzero = math.floor(b/(cd)) - math.floor((a-1)/(cd))

ans = b - a + 1 - (c_modzero + d_modzero - cd_modzero)

print(ans)

import math
import copy
import fractions
import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

num = getInputListInt()

a = num[0]
b = num[1]
c = num[2]
d = num[3]

c_modzero = math.floor(b/c) - math.floor((a-1)/c)
d_modzero = math.floor(b/d) - math.floor((a-1)/d)

cd = c * d / fractions.gcd(c, d)

cd_modzero = math.floor(b/cd) - math.floor((a-1)/cd)

ans = b - a + 1 - (c_modzero + d_modzero - cd_modzero)

print(int(ans))

import math
import copy
import fractions
import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

def GCD(x, y):
    return x if y == 0 else GCD(y, x % y)


def LCM(x, y):
    return x // GCD(x, y) * y

num = getInputListInt()

a = num[0]
b = num[1]
c = num[2]
d = num[3]

c_modzero = b//c - (a-1)//c
d_modzero = b//d - (a-1)//d

cd = LCM(c, d)

cd_modzero = b//cd - (a-1)//cd

ans = b - a + 1 - (c_modzero + d_modzero - cd_modzero)

print(int(ans))



Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Accepted