Problem:


Score : 300 points

Problem Statement

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.

Constraints

1\leq A\leq B\leq 10^{18}

1\leq C,D\leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Sample Input 1

4 9 2 3

Sample Output 1

2

5 and 7 satisfy the condition.

Sample Input 2

10 40 6 8

Sample Output 2

23

Sample Input 3

314159265358979323 846264338327950288 419716939 937510582

Sample Output 3

532105071133627368



Sample input:
4 9 2 3


Sample output:
2

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
def gcd(x,y):
  while y!=0:
    x,y=y,x%y
  return x
C=((b-a+1)//c)+(1 if (b-a+1)%c!=0 else 0)
D=((b-a+1)//d)+(1 if (b-a+1)%d!=0 else 0)
if c>d:
  CD=((b-a+1)//(c*d//gcd(c,d)))+(1 if (b-a+1)%(c*d//gcd(c,d))!=0 else 0)
else:
  CD=((b-a+1)//(c*d//gcd(d,c)))+(1 if (b-a+1)%(c*d//gcd(d,c))!=0 else 0)
print(b-a+1-C-D+CD)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
def gcd(x,y):
  while y!=0:
    x,y=y,x%y
  return x
C=((b-a+1)//c)+(1 if (b-a+1)%c!=0 else 0)
D=((b-a+1)//d)+(1 if (b-a+1)%d!=0 else 0)
if c>d:
  CD=((b-a+1)//gcd(c,d))+(1 if (b-a+1)%gcd(c,d)!=0 else 0)
else:
  CD=((b-a+1)//gcd(d,c))+(1 if (b-a+1)%gcd(d,c)!=0 else 0)
print(b-a+1-C-D+CD)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
def gcd(x,y):
  while y!=0:
    x,y=y,x%y
  return x
C=((b-a+1)//c)+1
D=((b-a+1)//d)+1
if c>d:
  CD=((b-a+1)//gcd(c,d))+1
else:
  CD=CD=((b-a+1)//gcd(d,c))+1
print(b-a+1-C-D+CD)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
C=0
D=0
CD=0
for i in range(a,b+1):
  if i%c==0 and i%d==0:
    CD+=1
  elif i%c==0:
    C+=1
  elif i%d==0:
    D+=1
print(b-a+1+CD-C-D)

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
lcm = c * d // fractions.gcd(c, d)
e = b // c - (a - 1) // c
f = b // d - (a - 1) // d
g = b // lcm + (a - 1) // lcm
print((b - a + 1) - (e + f - g))

Submission status: Wrong Answer

Solution code:
A,B,C,D = list(map(int, input().split()))
def GCD(x,y):
    n = min(x,y)
    for i in reversed(range(1,n+1)):
        if x%i==0 and y%i==0:
            break
    return i
a=(A-1)//C
b=B//C
c=(A-1)//D
d=B//D
g = C*D/GCD(C,D)
e=(A-1)//(g)
f=B//(g)

print(int(B-A+1 - (b-a) - (d-c) + (f-e)))

Submission status: Wrong Answer

Solution code:
A,B,C,D = list(map(int, input().split()))
a=(A-1)//C
b=B//C
c=(A-1)//D
d=B//D
e=(A-1)//(C*D)
f=B//(C*D)
print(B-A+1 - (b-a) - (d-c) + (f-e))

Submission status: Wrong Answer

Solution code:
from fractions import gcd 

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


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


def cnt_mod_0_num(source_int, divided_by):
  return source_int // divided_by


under_B = cnt_mod_0_num(B,C) + cnt_mod_0_num(B,D) - cnt_mod_0_num(B,lcm_C_D)
under_A_1 = cnt_mod_0_num(A-1,C) + cnt_mod_0_num(A-1,D) - cnt_mod_0_num(A-1,lcm_C_D)

ans = B - A - (under_B - under_A_1) + 1
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d = list(map(int, input().split()))
def euqlid(x,y):
    if x < y :
        temp = x
        x = y
        y = temp
    while x % y != 0:
        temp = x
        x = y
        y = temp % y
    return y
def searchCount(p,q,k):
    min = 0
    max = 0
    if p % k == 0:
        min = p / k
    else:
        min = p//k + 1
    max = q//k
    return int(max - min) + 1
lcm = euqlid(c,d)
gcd = int((c * d) / lcm)
print((b - a + 1) - searchCount(a,b,c) - searchCount(a,b,d) + searchCount(a,b,gcd))

Submission status: Wrong Answer

Solution code:
a, b, c, d = list(map(int, input().split()))
def euqlid(x,y):
    if x < y :
        temp = x
        x = y
        y = temp
    while x % y != 0:
        temp = x
        x = y
        y = temp % y
    return y
def searchCount(p,q,k):
    min = 0
    max = 0
    if a % k == 0:
        min = p
    else:
        min = p//k + 1
    max = q//k
    return int(max - min) + 1
lcm = euqlid(c,d)
gcd = int(c * d / lcm)
print((b - a + 1) - searchCount(a,b,c) - searchCount(a,b,d) + searchCount(a,b,gcd))

Submission status: Wrong Answer

Solution code:
a, b, c, d = list(map(int, input().split()))
def euqlid(x,y):
    if x < y :
        temp = x
        x = y
        y = temp
    while x % y != 0:
        temp = x
        x = y
        y = temp % y
    return y
def searchCount(p,q,k):
    min = 0
    max = 0
    if a % k == 0:
        min = p
    else:
        min = p//k + 1
    max = q//k
    return int(max - min) + 1
lcm = euqlid(c,d)
gcd = c * d / lcm
print((b - a + 1) - searchCount(a,b,c) - searchCount(a,b,d) + searchCount(a,b,gcd))

Submission status: Wrong Answer

Solution code:
a, b, c, d = list(map(int, input().split()))
def euqlid(x,y):
    if x < y :
        temp = x
        x = y
        y = temp
    while x % y != 0:
        temp = x
        x = y
        y = temp % y
    return y
def searchCount(a,b,k):
    min = 0
    max = 0
    if a % k == 0:
        min = a
    else:
        min = int(a/k) + 1
    max = int(b/k)
    return int(max - min) + 1

lcm = euqlid(c,d)
gcd = c * d / lcm
print((b - a + 1) - searchCount(a,b,c) - searchCount(a,b,d) + searchCount(a,b,gcd))

Submission status: Wrong Answer

Solution code:
a, b, c, d = list(map(int, input().split()))
def euqlid(x,y):
    if x < y :
        temp = x
        x = y
        y = temp
    while x % y != 0:
        temp = x
        x = y
        y = temp % y
    return y
def searchCount(a,b,k):
    min = 0
    max = 0
    if a % k == 0:
        min = a
    else:
        min = (int(a/k) + 1) * k
    max = int(b/k) * k
    return int((max - min) / k) + 1


lcm = euqlid(c,d)
gcd = c * d / lcm
print((b - a + 1) - searchCount(a,b,c) - searchCount(a,b,d) + searchCount(a,b,gcd))

Submission status: Wrong Answer

Solution code:
import math
import fractions

a, b, c, d = map(int, input().split())

a_c = (a - 1) // c
b_c = b // c
a_d = (a - 1) // d
b_d = b // d

lcm = c * d / fractions.gcd(c, d)
a_cd = (a - 1) // lcm
b_cd = b // lcm

result = b - a + 1 - (b_c - a_c) - (b_d - a_d) + (b_cd - a_cd)
print(int(result))

Submission status: Wrong Answer

Solution code:
import math
import fractions

a, b, c, d = map(int, input().split())

a_c = math.ceil(a / c)
b_c = math.floor(b / c)
a_d = math.ceil(a / d)
b_d = math.floor(b / d)

lcm = c * d / fractions.gcd(c, d)
a_cd  = math.ceil(a / lcm)
b_cd = math.floor(b / lcm)

result = b - a + 1 - (b_c - a_c + 1) - (b_d - a_d + 1) + (b_cd - a_cd + 1)
print(result)

Submission status: Wrong Answer

Solution code:
import math
import fractions

a, b, c, d = map(int, input().split())

a_c = math.ceil(a / c)
b_c = math.floor(b / c)
a_d = math.ceil(a / d)
b_d = math.floor(b / d)

lcm = c * d / fractions.gcd(c, d)
a_cd  = math.ceil(a / lcm)
b_cd = math.floor(b / lcm)

result = b - a + 1
if a_c != 0 and b_c != 0:
  result -= b_c - a_c + 1
if a_d != 0 and b_d != 0:
  result -= b_d - a_d + 1
if a_cd != 0 and b_cd != 0:
  result += b_cd - a_cd + 1
print(result)

Submission status: Wrong Answer

Solution code:
import math
import fractions

a, b, c, d = map(int, input().split())

a_c = math.ceil(a / c)
b_c = math.floor(b / c)
a_d = math.ceil(a / d)
b_d = math.floor(b / d)

lcm = c * d / fractions.gcd(c, d)
a_cd  = math.ceil(a / lcm)
b_cd = math.floor(b / lcm)

result = b - a + 1
if a_c != 0:
  result -= b_c - a_c + 1
if a_d != 0:
  result -= b_d - a_d + 1
if a_cd != 0:
  result += b_cd - a_cd + 1
print(result)

Submission status: Wrong Answer

Solution code:
import math
import fractions

a, b, c, d = map(int, input().split())

a_c = math.ceil(a / c)
b_c = math.floor(b / c)
a_d = math.ceil(a / d)
b_d = math.floor(b / d)

lcm = c * d / fractions.gcd(c, d)
a_cd  = math.ceil(a / lcm)
b_cd = math.floor(b / lcm)

print(b - a + 1 - (b_c - a_c + 1) - (b_d - a_d + 1) + (b_cd - a_cd + 1))

Submission status: Wrong Answer

Solution code:
import math
a, b, c, d = map(int, input().split())

a_c = math.ceil(a / c)
b_c = math.floor(b / c)
a_d = math.ceil(a / d)
b_d = math.floor(b / d)
a_cd = math.ceil(a / (c * d))
b_cd = math.floor(b / (c * d))

print(b - a + 1 - (b_c - a_c + 1) - (b_d - a_d + 1) + (b_cd - a_cd + 1))

Submission status: Wrong Answer

Solution code:
# Anti-Division
A, B, C, D = map(int, input().split())


w = B // C
x = B // D
y = (A - 1) // C
z = (A - 1) // D
a = B // (C * D)
b = (A - 1) // (C * D)

ans = (B-A+1) - ((w-y)+(x-z)-(a-b))
print(ans)

Submission status: Wrong Answer

Solution code:
# Anti-Division
A, B, C, D = map(int, input().split())

count1 = 0
count2 = 0
count3 = 0
w = 0
x = 0
y = 0
for i in range(A, B):
    if i % C == 0:
        w = i
        break

for j in range(A, B):
    if j % D == 0:
        x = j
        break

for k in range(w, B + 1, C):
    count1 = count1 + 1

for l in range(x, B + 1, D):
    count2 = count2 + 1

for m in range(A, B):
    if m % (C * D) == 0:
        y = m
        break

for n in range(y, B + 1, C*D):
    count3 = count3 + 1

ans = B - A + 1 - (count1 + count2 - count3)

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
A, B, C, D = map(int, str(input()).split())

total_num = B - A + 1

can_C_divided = B // C - A // C
can_D_divided = B // D - A // D
lcm = C * D // fractions.gcd(C, D)
can_CD_divided = B // lcm - A // lcm

print(total_num - can_C_divided - can_D_divided + can_CD_divided)

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d = map(int, input().split())

# a~bの数でcで割り切れる数の個数は
divC = b//c - a//c
# a~bの数でdで割り切れる数の個数は
divD = b//d - a//d
# a~bの数でc,dの最小公倍数で割り切れる数の個数は
l = (c*d) // fractions.gcd(c,d)
divU= b//l - a//l
divSum = divC+divD-divU
print(b-a+1 - divSum)

Submission status: Wrong Answer

Solution code:
from math import ceil
from fractions import gcd


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


a, b, c, d = map(int, input().split())

A = b // c - ceil(a / c) + 1
B = b // d - ceil(a / d) + 1

C = b // lcm(c, d) - ceil(a / lcm(c, d)) + 1
print(b-a+1-(A+B-C))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d=map(int,input().split())

ce=b//c
if a<=ce*c and ce*c<=b:
    cs=1+((a-1)//c)
else:
    cs=ce-1

de=b//d
if a<=de*d and de*d<=b:
    ds=1+((a-1)//d)
else:
    ds=de-1

gg=(c*d)//gcd(c,d)
cde=b//gg
if a<=cde*gg and cde*gg<=b:
    cds=1+((a-1)//gg)
else:
    cds=cde-1

#print(cs,ce,ds,de,cds,cde)
print(int(b-a-ce-de+cs+ds+cde-cds))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d=map(int,input().split())

ce=b//c
if ce!=0:
    cs=1+((a-1)//c)
else:
    cs=-1

de=b//d
if de!=0:
    ds=1+((a-1)//d)
else:
    ds=-1

gg=(c*d)//gcd(c,d)
cde=b//gg
if cde!=0:
    cds=1+((a-1)//gg)
else:
    cds=-1

#print(cs,ce,ds,de,cds,cde)
print(int(b-a-ce-de+cs+ds+cde-cds))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d=map(int,input().split())

ce=b//c
if ce!=0:
    cs=1+((a-1)//c)
else:
    cs=0

de=b//d
if de!=0:
    ds=1+((a-1)//d)
else:
    ds=0

gg=(c*d)//gcd(c,d)
cde=b//gg
if cde!=0:
    cds=1+((a-1)//gg)
else:
    cds=0

print(int(b-a-ce-de+cs+ds+cde-cds))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int,input().split())
l = (c*d) / gcd(c,d)

x = b//c - (a-1)//c
y = b//d - (a-1)//d
z = b//l - (a-1)//l
s = int(x+y-z)

print(b-a+1-s)

Submission status: Wrong Answer

Solution code:
#2パターンWA

def gcd(x,y):
    while y != 0:
        x,y = y,x%y
    return x
def lcm(x,y):
    return x*y//gcd(x,y)

a, b, c, d = (int(i) for i in input().split())

V = b - a + 1
ans = 0
if V != 1:
    if a%c != 0:
        c_cnt = len(range(a+(c - a%c),b+1,c))
    else:
        c_cnt = len(range(a,b+1,c))

    if a%d != 0:
        d_cnt = len(range(a+(d - a%d),b+1,d))
    else:
        d_cnt = len(range(a,b+1,d))

    cd_lcm = lcm(c,d)
    if (cd_lcm - a%(cd_lcm)) != 0:
        cd_cnt = len(range(a+(cd_lcm - a%(cd_lcm)),b+1,cd_lcm))
    else:
        cd_cnt = len(range(a,b+1,cd_lcm))

    ans = V - (c_cnt + d_cnt - cd_cnt)
else:
    if a%c != 0 and a%d != 0:
        ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
    while y != 0:
        x,y = y,x%y
    return x
def lcm(x,y):
    return x*y//gcd(x,y)

a, b, c, d = (int(i) for i in input().split())

V = b - a + 1
if a%c != 0:
    c_cnt = len(range(a+(c - a%c),b+1,c))
else:
    c_cnt = len(range(a,b+1,c))

if a%d != 0:
    d_cnt = len(range(a+(d - a%d),b+1,d))
else:
    d_cnt = len(range(a,b+1,d))

cd_lcm = lcm(c,d)
if (cd_lcm - a%(cd_lcm)) != 0:
    cd_cnt = len(range(a+(cd_lcm - a%(cd_lcm)),b+1,cd_lcm))
else:
    cd_cnt = len(range(a,b+1,cd_lcm))

ans = V - (c_cnt + d_cnt - cd_cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
[A, B, C, D] = map(int, input().split())

def gcd(x, y):
    if x > y:
        z = x % y
        if z == 0:
            return y
        else:
        	return gcd(z, y)
    elif x < y:
        z = y % x
        if z == 0:
            return x
        else:
            return gcd(x, z)
    else: # x == y
        return x

lcmCD = int(C * D / gcd(C, D))

res = B - int(B / C) - int(B / D) + int(B / lcmCD) - (A-1) + int((A-1) / C) + int((A-1) / D) - int((A-1) / lcmCD)
print(res)

Submission status: Wrong Answer

Solution code:
# Anti-Division
A, B, C, D = map(int,input().split())

count = 0
for i in range(A,B):
    if i % C > 0 and i % D > 0:
        count = count + 1
    else:
        pass
print(count)

Submission status: Wrong Answer

Solution code:
[A, B, C, D] = map(int, input().split())

def gcd(x, y):
    if x > y:
        z = x % y
        if z == 0:
            return y
        else:
        	return gcd(z, y)
    elif x < y:
        z = y % x
        if z == 0:
            return x
        else:
            return gcd(x, z)
    else: # x == y
        return x

lcmCD = int(C * D / gcd(C, D))

# 1 以上 x 以下の整数のうち、C でも D でも割り切れないものの個数
def calc(x):
    return x - (int(x / C) + int(x / D) - int(x / lcmCD))

res = int(calc(B) - calc(A - 1))
print(res)

Submission status: Wrong Answer

Solution code:
[A, B, C, D] = map(int, input().split())

def gcd(x, y):
    if x > y:
        z = x % y
        if z == 0:
            return y
        else:
        	return gcd(z, y)
    elif x < y:
        z = y % x
        if z == 0:
            return x
        else:
            return gcd(x, z)
    else: # x == y
        return x

lcmCD = int(C * D / gcd(C, D))

# 1 以上 x 以下の整数のうち、C でも D でも割り切れないものの個数
def calc(x):
    return x - (int(x / C) + int(x / D) - int(x / lcmCD))

res = calc(B) - calc(A - 1)
print(res)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

[A, B, C, D] = map(int, input().split())
lcmCD = int(C * D / gcd(C, D))

# 1 以上 x 以下の整数のうち、C でも D でも割り切れないものの個数
def calc(x):
    return x - (int(x / C) + int(x / D) - int(x / lcmCD))

res = max(calc(B) - calc(A - 1), 0)
print(res)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

[A, B, C, D] = map(int, input().split())
lcmCD = int(C * D / gcd(C, D))

# 1 以上 x 以下の整数のうち、C でも D でも割り切れないものの個数
def calc(x):
    return x - (int(x / C) + int(x / D) - int(x / lcmCD))

res = calc(B) - calc(A - 1)
print(res)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

[A, B, C, D] = map(int, input().split())
lcmCD = C * D / gcd(C, D)

# 1 以上 x 以下の整数のうち、C でも D でも割り切れないものの個数
def calc(x):
    return x - int(x / C) - int(x / D) + int(x / lcmCD)

res = calc(B) - calc(A - 1)
print(res)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())

ce=b//c
if ce!=0:
    cs=1+((a-1)//c)
else:
    cs=0

de=b//d
if de!=0:
    ds=1+((a-1)//d)
else:
    ds=0

cde=b//(c*d)
if cde!=0:
    cds=1+((a-1)//(c*d))
else:
    cds=0

print(int(b-a-ce-de+cs+ds+cde-cds))

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())

# 最大公約数
def gcd(a, b):
    while a%b!=0:
        a, b = b, a%b
    return b

X = b//c - (a-1)//c
Y = b//d - (a-1)//d
# 最小公倍数
CD = c*d / gcd(c, d)
XY = b//CD - (a-1)//CD

print(b-a+1-(X+Y-XY))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from math import ceil,floor

(A,B,C,D)=( int ( x ) for x in input().split(" ") )
E = int ( C * D / gcd(C,D) )

print ( B - A - ( floor  ( B/C ) - ceil ( A/C ) + floor  ( B/D ) - ceil ( A/D ) + 1 - floor  ( B/E ) + ceil ( A/E ) - 1 ) )

Submission status: Wrong Answer

Solution code:
def main():
    tmp = list(map(int, input().split(" ")))
    a = tmp[0]
    b = tmp[1]
    c = tmp[2]
    d = tmp[3]

    ans = f(b, c, d) - f(a-1, c, d)
    print(ans)


def gcd(c, d):
    big = max(c, d)
    small = min(c, d)
    if small == 0:
        return int(big)
    r = big % small
    return gcd(small, r)


def f(x, c, d):
    return x - (x//c) - (x//d) + int(x // ((c*d) / gcd(c, d)))

main()

Submission status: Wrong Answer

Solution code:
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

a,b,c,d=[int(x) for x in input().split()]

abletodiv=(b//c - (a-1)//c) + (b//d - (a-1)//d) -(b//lcm(c,d) - (a-1)//lcm(c,d))
#print(abletodiv)
#print((b//c - (a-1)//c),(b//d - (a-1)//d),(b//lcm(c,d) - (a-1)//lcm(c,d)))
print("ans=",b-a+1-abletodiv)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
def gcd(x,y):
  while y:
    x,y = y,x%y
  return x
def lcm(x,y):
  return (x*y) // gcd(x,y)
e = lcm(c,d)
C = int(b/c) - int((a-1)/c)
D = int(b/d) - int((a-1)/d)
CD = int(b/e) - int((a-1)/e)
print(b-a+1-(C+D-CD))

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())

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

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

if A%C == 0:
    start1 = A // C
else:
    start1 = A // C
    if start1 > 0:
        start1 += 1


if A%D == 0:
    start2 = A // D
else:
    start2 = A // D
    if start2 > 0:
        start2 += 1


tmp = lcm(C, D)


if A%(C*D) == 0:
    start3 = A // tmp
else:
    start3 = A // tmp
    start3 += 1

end1 = B // C
end2 = B // D
end3 = B // tmp


res = (B - A + 1) - (end1 - start1 + 1) - (end2 - start2 + 1) + (end3 - start3 + 1)


print(res)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
e = lcm(c,d)
C = int(b/c) - int((a-1)/c)
D = int(b/d) - int((a-1)/d)
CD = int(b/e) - int((a-1)/e)
print(b-a+1-(C+D-CD))

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())

if A%C == 0:
    start1 = A // C
else:
    start1 = A // C
    if start1 > 0:
        start1 += 1


if A%D == 0:
    start2 = A // D
else:
    start2 = A // D + 1
    if start2 > 0:
        start2 += 1

if A%(C*D) == 0:
    start3 = A // (C*D)
else:
    start3 = A // (C*D) + 1
    if start3 > 0:
        start3 += 1

end1 = B // C
end2 = B // D
end3 = B // (C*D)


res = (B - A + 1) - (end1 - start1 + 1) - (end2 - start2 + 1) + (end3 - start3 + 1)

print(res)

Submission status: Wrong Answer

Solution code:
num = [int(i) for i in input().split()]
lower_limit = num[0]
upper_limit = num[1]
c = num[2]
d = num[3]

def count_multi(x):
  count = upper_limit//x- (lower_limit-1)//x
                                 
  return count

multi_c_d = count_multi(c) + count_multi(d) - count_multi(c*d)
print(upper_limit - lower_limit + 1 - multi_c_d)

Submission status: Wrong Answer

Solution code:
num = [int(i) for i in input().split()]
lower_limit = num[0]
upper_limit = num[1]
c = num[2]
d = num[3]

def count_multi(x):
  count = (upper_limit - lower_limit) // x
  if upper_limit % x == 0 or lower_limit % x == 0:
    count += 1
  return count

multi_c_d = count_multi(c) + count_multi(d) - count_multi(c*d)
print(upper_limit - lower_limit + 1 - multi_c_d)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

a, b, c, d = map(int, input().split())
a -= 1

def main():
    cd = c * d / gcd(c, d)
    print(b - a - (f(c) + f(d) - f(cd)))

def f(x):
    return int(b // x - a // x)

main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd

a, b, c, d = map(int, input().split())

def main():
    cd = c * d / gcd(c, d)
    print(b - a - (f(c) + f(d) - f(cd)) + 1)

def f(x):
    return int(b // x - a // x)

main()

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

a, b, c, d = map(int, input().split())

def main():
    cd = c * d / gcd(c, d)
    print(b - a - (f(c) + f(d) - f(cd)) + 1)

def f(x):
    return math.floor((b - x * math.ceil(a / x)) / x) + 1

main()

Submission status: Wrong Answer

Solution code:
import fractions
num = [int(i) for i in input().split()]
ans = 0
cd_gcd = fractions.gcd(num[2], num[3])
for i in range(num[0], num[1]+1):
  if cd_gcd != 1 and i%cd_gcd == 0:
    continue
  elif i%num[2] != 0 and i%num[3] != 0:
    ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
num = [int(i) for i in input().split()]

list_count = [0] * 3

c_begin = num[0] // num[2]
count = 1
temp = num[2] * (c_begin + count)
while temp <= num[1]:
	count += 1
	temp = num[2] * (c_begin + count)
count += -1
list_count[0] = count
    
    
d_begin = num[0] // num[3]
count = 1
temp = num[3] * (d_begin + count)
while temp <= num[1]:
	count += 1
	temp = num[3] * (d_begin + count)
count += -1
list_count[1] = count

cd_begin = num[0] // (num[2] * num[3])
count = 1
temp = num[2] * num[3] * (cd_begin + count)
while temp <= num[1]:
	count += 1
	temp = num[2] * num[3] * (cd_begin + count)
count += -1
list_count[2] = count

ans = num[1] - num[0] + 1 - (list_count[0] + list_count[1] - list_count[2])


print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
def cnt(x):
  return ((b-b%x)-((a-1)-(a-1)%x+x))//x+1
print((b-a+1)-cnt(c)-cnt(d)+int(cnt(c*d/fractions.gcd(c,d))))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
def cnt(x):
  return ((b-b%x)-((a-1)-(a-1)%x+x))//x+1
print(int((b-a+1)-cnt(c)-cnt(d)+cnt(c*d/fractions.gcd(c,d))))

Submission status: Wrong Answer

Solution code:
import fractions

a, b, c, d = list(map(int, input().split()))


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


def ans(x):
    can_div_c_count = x // c
    can_div_d_count = x // d
    can_div_lcm_count = x // lcm(c, d)
    return x - (can_div_c_count + can_div_d_count - can_div_lcm_count)


print(ans(b)-ans(a))

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())

ans1 = (B // C) + (B // D) - (B // (C * D))
ans2 = ((A - 1) // C) + ((A - 1) // D) - ((A - 1) // (C * D))

print(B- A + 1 - ans1 + ans2)

Submission status: Wrong Answer

Solution code:
import math
import fractions
a,b,c,d = map(int, input().split())
e = a-1
less_than_e = e - math.floor(e/c) - math.floor(e/d) + math.floor(e/(c*d//fractions.gcd(c,d)))
less_than_b = b - math.floor(b/c) - math.floor(b/d) + math.floor(b/(c*d//fractions.gcd(c,d)))
print(less_than_b - less_than_e)

Submission status: Wrong Answer

Solution code:
import math
import fractions
a,b,c,d = map(int, input().split())
e = a-1
gcd = fractions.gcd(c,d)
less_than_e = e - (e//c) - (e//d) + (e//(c*d/gcd))
less_than_b = b - (b//c) - (b//d) + (b//(c*d/gcd))
if less_than_e < 0:
    less_than_e = 0
print(less_than_b - less_than_e)

Submission status: Wrong Answer

Solution code:
import math
import fractions
a,b,c,d = map(int, input().split())
e = a-1
less_than_e = e - math.floor(e/c) - math.floor(e/d) + math.floor(e/(c*d/fractions.gcd(c,d)))
less_than_b = b - math.floor(b/c) - math.floor(b/d) + math.floor(b/(c*d/fractions.gcd(c,d)))
print(less_than_b - less_than_e)

Submission status: Wrong Answer

Solution code:
import math

def gcd(x,y):
  M=max(x,y)
  m=min(x,y)
  while(M%m!=0):
      r=M%m
      M=m
      m=r
  return m



def f(x,y):
  z=x//y
  return z


a,b,c,d=map(int,input().split())
g=gcd(c,d)
p=a-f(a,c)-f(a,d)+f(a,c*d/g)
q=b-f(b,c)-f(b,d)+f(b,c*d/g)
if(a%c!=0 and a%d!=0):
  print(q-p+1)
else:
  print(q-p)

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
c_min=0
d_min=0
cd_min=0
c_max=0
d_max=0
cd_max=0
cd=(c*d)//fractions.gcd(c,d)

c_min=a%c
c_max=b%c
d_min=a%d
d_max=b%d
cd_min=a%cd
cd_max=b%cd


countc=(b-c_max-a+c_min+1)//c
countd=(b-d_max-a+d_min+1)//d
countcd=(b-cd_max-a+cd_min+1)//cd
print(b-a+1-countc-countd+countcd)

Submission status: Wrong Answer

Solution code:
import fractions
A, B, C, D = map(int, input().split())
CD = C * D // fractions.gcd(C,D)
n_divC = B // C - A // C
n_divD = B // D - A // D
n_divCD = B // CD - A // CD
ans = B - A + 1 - n_divC - n_divD + n_divCD
print(ans)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
n_divC = B // C - A // C
n_divD = B // D - A // D
n_divCD = B // (C*D) - A // (C*D)
ans = B - A + 1 - n_divC - n_divD + n_divCD
print(ans)

Submission status: Wrong Answer

Solution code:

def gcd(x,y):
    z = max(x,y)
    a = 1
    for i in range(1,z+1):
        if x%i == 0 and y%i == 0:
            a = i
    return a


A,B,C,D = (int(i) for i in input().split())
C_div = int(0)
D_div = int(0)
CandD_div = int(0)
E =int(C*D/gcd(C,D))

if A%C == 0:
    C_div = int(B/C) - int(A/C) + 1
else:
    C_div = int(B/C) - int(A/C)

if A%D == 0:
    D_div = int(B/D) - int(A/D) + 1
else:
    D_div = int(B/D)- int(A/D)


if A%E == 0:
    CandD_div  = int(B/E) - int(A/E) + 1
else:
    CandD_div  = int(B/E)- int(A/E)


ans = B - A + 1 - (C_div + D_div - CandD_div)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

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

M=fractions.gcd(C,D)
LCM=C*D/M
VB=B-((B//C)+(B//D)-(B//LCM))

VA=(A-1)-(((A-1)//C)+((A-1)//D)-((A-1)//LCM))
print(int(VB-VA))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())

def lcm(n, h):
    return (n * h) // fractions.gcd(n, h)

def slove(x, y, z):
	return (x//y) + (x//z) - (x//lcm(y,z))

print(b - a + 1 +slove(b,c,d) - slove(a-1,c,d))

Submission status: Wrong Answer

Solution code:
import math
import fractions


def count_multiple(A, B, x):
    min_value = math.ceil(A / x)
    max_value = B // x
    
    return max_value - min_value + 1


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

lcm = C * D // fractions.gcd(C, D)
cnt = 0
for i, x in enumerate([C, D, lcm]):
    if i < 2:
        cnt += count_multiple(A, B, x)
    else:
        cnt -= count_multiple(A, B, x)

total = B - A + 1
ans = total - cnt
print(ans)

Submission status: Wrong Answer

Solution code:
A, B, C, D = (int(i) for i in input().split()) 
c=0
d=0
cd=0


for i in range(A-1):
  if i+1%C==0:
    c+=1
  if i+1%D==0:
    d+=1
  if i+1%(C*D)==0:
    cd+=1
a=A-1-c-d+cd
c=0
d=0
cd=0
for i in range(B):
  if i+1%C==0:
    c+=1
  if i+1%D==0:
    d+=1
  if i+1%(C*D)==0:
    cd+=1
b=B-c-d+cd
print(b-a)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
E = A - 1

x = B - (int(B//C)+int(B//D) - int(B//(C*D)))
y = E - (int(E//C)+int(E//D) - int(E//(C*D)))

print(x-y)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
E = A - 1

x = B - (int(B/C)+int(B/D) - int(B/(C*D)))
y = E - (int(E/C)+int(E/D) - int(E/(C*D)))

print(x-y)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
E = A - 1
x = B - (int(B/C)+int(B/D) - int(B/(C*D)))
y = E - (int(E/C)+int(E/D) - int(E/(C*D)))
X = int(x)
Y = int(y)
print(X - Y)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
E = A - 1
x = B - ((B/C)+(B/D) - (B/(C*D)))
y = E - ((E/C)+(E/D) - (E/(C*D)))
X = int(x)
Y = int(y)
print(X - Y)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())

num = 0
if A != B:
    for i in range(A,B):
        if i%C == 0:
            num += 0
        else:
            if i%D == 0:
                num += 0
            else:
                num += 1
else:
    if A%C != 0 and A%D != 0:
        num += 1
    else:
        num += 0
print(num)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())

num = 0
for i in range(A,B):
    if i%C != 0 and i%D != 0:
        num += 1
    else:
        num += 0
print(num)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())

num = 0
if A != B:
    for i in range(A,B):
        if i%C != 0 and i%D != 0:
            num += 1
        else:
            num += 0
else:
    if A%C != 0 and A%D != 0:
        num += 1
    else:
        num += 0
print(num)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())

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

N = B//C+B//D-B//C//D*gcd(C,D)-(A-1)//C-(A-1)//D+(A-1)//C//D*gcd(C,D)
print (B-A+1-N)

Submission status: Wrong Answer

Solution code:
def gcd(num1, num2):
  while num2!=0:
    num1, num2 = num2, num1%num2
  return num1

a, b, c, d = map(int,input().split())
bb = b-(b//c + b//d)
aa = (a-1)-((a-1)//c + (a-1)//d)
l = int(c*d/gcd(c, d))
ll = b//l
print(bb-aa+ll)

Submission status: Wrong Answer

Solution code:
def main():
  a, b, c, d = list(map(int, input().split(' ')))
  res = cal(a, b, c) + cal(a, b, d) - cal(a, b, c*d)
  print((b-a+1)-res)


def cal(l, r, n):
  a = r / n - l / n
  return int(a if a % 1 == 0 else a // 1 + 1)


if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
def euclidean(a,b):
    if b == 0:
        return a
    else :
        return euclidean(b,a%b)
 
def gcd(a,b):
    if a == b:
        return a
    elif a > b:
        return euclidean(a,b)
    else :
        return euclidean(b,a)
 
def anti_division(a,b,c,d):
    ans = 0
#    import pdb;pdb.set_trace()
 
    if a == b:
        if a%c != 0 or b%d != 0:
            return 1
 
    g = gcd(c,d)
    l = c*d//g
    ua = a - 1
 
    dupb = b//l
    numbc  = b//c
    numbd  = b//d
 
    dupa = ua//l
    numac  = ua//c
    numad  = ua//d
 
    ans = b - ua - (numbc - numac) - (numbd - numad) + dupb + dupa
 
    return ans
if __name__ == '__main__':
    a,b,c,d = map(int,raw_input().split())
    print anti_division(a,b,c,d)

Submission status: Wrong Answer

Solution code:
def euclidean(a,b):
    if b == 0:
        return a
    else :
        return euclidean(b,a%b)

def gcd(a,b):
    if a == b:
        return a
    elif a > b:
        return euclidean(a,b)
    else :
        return euclidean(b,a)

def anti_division(a,b,c,d):
    ans = 0
#    import pdb;pdb.set_trace()

    if a == b:
        if a%c != 0 and b%d != 0:
            return 1

    g = gcd(c,d)
    l = c*d//g
    ua = a - 1

    dupb = b//l
    numbc  = b//c
    numbd  = b//d

    dupa = ua//l
    numac  = ua//c
    numad  = ua//d

    ans = b - ua - (numbc - numac) - (numbd - numad) + dupb + dupa

    return ans
if __name__ == '__main__':
    a,b,c,d = map(int,raw_input().split())
    print anti_division(a,b,c,d)

Submission status: Wrong Answer

Solution code:
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def diff(i, j, k):
	return i - (i//j) - (i//k) + (i//lcm(j,k))

a,b,c,d = map(int, input().split())

print( diff(b, c, d) - diff(a, c, d) )

Submission status: Wrong Answer

Solution code:
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def diff(i, j, k):
	return (j // k) - ( i // k)

a,b,c,d = map(int, input().split())

zedd = diff(a-1, b+1, c) + diff(a-1, b+1, d) - diff(a-1, b+1, lcm(c,d))
ans = (b-a+1) -zedd

print(ans)