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:
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 = 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 = (A - 1) - (num_A_1 + num_A_2 - num_A_3)

print(num_B - num_A)

Submission status: Wrong Answer

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

def multiple(X, Y, Z):
    min_z = X // Z + 1
    max_z = Y // Z 
    num_z = max_z - min_z + 1
    return num_z 

def gcd(X, Y):
    while Y!= 0:
        X, Y = Y, X % Y
    return X

if C == 1 or D == 1:
    print(0)
else:
    num_c = multiple(A, B, C)
    print(num_c)
    num_d = multiple(A, B, D)
    print(num_d)
    lcm = int((C * D) / gcd(C, D)) 
    num_lcm = multiple(A, B, lcm)
    print(B - A + 1 - num_c - num_d + num_lcm)

Submission status: Wrong Answer

Solution code:
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 * D / g

num_B_1 = math.floor(B / C)
num_B_2 = math.floor(B / D)
num_B_3 = math.floor(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 = (A - 1) - (num_A_1 + num_A_2 - num_A_3)

print(num_B - num_A)

Submission status: Wrong Answer

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

def multiple(X, Y, Z):
    min_z = math.ceil(X / Z)
    max_z = math.floor(Y / Z) 
    z_num = max_z - min_z + 1
    return z_num

def gcd(X, Y):
    while Y!= 0:
        X, Y = Y, X % Y
    return X

if C == 1 or D == 1:
    print(0)
elif A == B:
    if A % C == 0 or A % D == 0:
        print(0)
    else:
        print(1)
else:
    num_c = multiple(A, B, C)
    num_d = multiple(A, B, D)

    lcm = int((C * D) / gcd(C, D)) 
    num_lcm = multiple(A, B, lcm)

    print(B - A + 1 - num_c - num_d + num_lcm)

Submission status: Wrong Answer

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

def multiple(X, Y, Z):
    min_z = math.ceil(X / Z)
    max_z = math.floor(Y / Z) 
    z_num = max_z - min_z + 1
    return z_num

def gcd(X, Y):
    while Y!= 0:
        X, Y = Y, X % Y
    return X

if C == 1 or D == 1:
    print(0)
else:
    num_c = multiple(A, B, C)
    num_d = multiple(A, B, D)

    lcm = int((C * D) / gcd(C, D)) 
    num_lcm = multiple(A, B, lcm)

    print(B - A + 1 - num_c - num_d + num_lcm)

Submission status: Wrong Answer

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

def multiple(X, Y, Z):
    min_z = math.ceil(X / Z)
    max_z = math.floor(Y / Z) 
    z_num = max_z - min_z + 1
    return z_num

def gcd(X, Y):
    while Y!= 0:
        X, Y = Y, X % Y
    return X

if A == B:
    if A % C == 0 or A % D == 0:
        print(0)
    else:
        print(1)
else:
    num_c = multiple(A, B, C)
    num_d = multiple(A, B, D)

    lcm = int((C * D) / gcd(C, D)) 
    num_lcm = multiple(A, B, lcm)

    print(B - A + 1 - num_c - num_d + num_lcm)

Submission status: Wrong Answer

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

def multiple(X, Y, Z):
    min_z = math.ceil(X / Z)
    max_z = math.floor(Y / Z) 
    z_num = max_z - min_z + 1
    return z_num

def gcd(X, Y):
    while Y!= 0:
        X, Y = Y, X % Y
    return X

num_c = multiple(A, B, C)
num_d = multiple(A, B, D)

lcm = int((C * D) / gcd(C, D)) 
num_lcm = multiple(A, B, lcm)

print(B - A + 1 - num_c - num_d + num_lcm)

Submission status: Wrong Answer

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


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


A, B, C, D = map(int, input().split())
c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
c_d = B // lcm(C, D) - (A - 1) // (C * D)
print(B - A + 1 - c - d + c_d)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
def gcd(x,y):
  if x%y==0:
    return y
  else:
    return gcd(y,x%y)
    
r=(c*d)/gcd(c,d)    
s=(b//c)-((a-1)//c)
t=(b//d)-((a-1)//d)
u=(b//r)-((a-1)//r)

print(int(b-a+1-s-t+u))

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
def gcd(x,y):
  if x%y==0:
    return y
  else:
    return gcd(y,x%y)
    
r=gcd(c,d)    
s=(b//c)-((a-1)//c)
t=(b//d)-((a-1)//d)
u=(b//r)-((a-1)//r)

print(b-a+1-s-t+u)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
t=(b//c-(a-1)//c)+(b//d-(a-1)//d)-(b//(c*d)-(a-1)//(c*d))
print(b-a+1-t)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
t=(b//c-a//c)+(b//d-a//d)-(b//c*d-a//c*d)
print(b-a+1-t)

Submission status: Wrong Answer

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


def p_c():
    A, B, C, D = map(int, input().split())
    A -= 1
    gcd_value = gcd(max(C, D), min(C, D))
    lcm_value = C * D // gcd_value
    print(B - A - B // C + A // C - B // D + A // D - B // lcm_value + A // lcm_value)
    
p_c()

Submission status: Wrong Answer

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


def p_c():
    A, B, C, D = map(int, input().split())
    gcd_value = gcd(max(C, D), min(C, D))
    lcm_value = C * D // gcd_value
    print(B - A - B // C + A // C - B // D + A // D - B // lcm_value + A // lcm_value)
    
p_c()

Submission status: Wrong Answer

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


def p_c():
    A, B, C, D = map(int, input().split())
    gcd_value = gcd(max(C, D), min(C, D))
    lcm_value = C * D // gcd_value
    ans = B - A
    print(ans - ans // C - ans // D + ans // lcm_value)
    
p_c()

Submission status: Wrong Answer

Solution code:
import math
import fractions

a, b, c, d = map(int, input().split())
# print(b - a + 1)
e = c * d // fractions.gcd(c, d)
cMax = math.ceil(a / c)
cMin = math.floor(b / c)
# print(cMin - cMax + 1)
dMax = math.ceil(a / d)
dMin = math.floor(b / d)
# print(dMin - dMax + 1)
eMax = math.ceil(a / e)
eMin = math.floor(b / e)
# print(eMin - eMax + 1)

print(b - a + 1 + eMin - eMax + 1 - (cMin - cMax + 1) - (dMin - dMax + 1))

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
  if a%b == 0:
    return b
  else:
    return gcd(b, a%b)
a, b, c, d = map(int, input().split())
n = b - a + 1
mod_c = (n + a%c - 1)//c + 1 if a%c == 0 else (n + a%c - 1)//c
mod_d = (n + a%d - 1)//d + 1 if a%d == 0 else (n + a%d - 1)//d
mod_cd = (n + a%(c*d/gcd(c, d)) - 1)//(c*d/gcd(c,d)) + 1 if a%(c*d/gcd(c,d)) == 0 else (n + a%(c*d/gcd(c,d)) - 1)//(c*d/gcd(c,d))
ans = n - mod_c - mod_d + mod_cd
print(int(ans))

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
n = b - a + 1
mod_c = (n + a%c - 1)//c + 1 if a%c == 0 else (n + a%c - 1)//c
mod_d = (n + a%d - 1)//d + 1 if a%d == 0 else (n + a%d - 1)//d
if max(c,d)%min(c,d) == 0:
  mod_cd = min(mod_c, mod_d)
else:
  mod_cd = (n + a%(c*d) - 1)//(c*d) + 1 if a%(c*d) == 0 else (n + a%(c*d) - 1)//(c*d)
ans = n - mod_c - mod_d + mod_cd
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
n = b - a + 1
mod_c = (n + a%c - 1)//c + 1 if a%c == 0 else (n + a%c - 1)//c
mod_d = (n + a%d - 1)//d + 1 if a%d == 0 else (n + a%d - 1)//d
mod_cd = (n + a%(c*d) - 1)//(c*d) + 1 if a%(c*d) == 0 else (n + a%(c*d) - 1)//(c*d)
ans = n - mod_c - mod_d + mod_cd
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
n = b - a + 1
mod_c = (n + a%c)//c
mod_d = (n + a%d)//d
mod_cd = (n + a%(c*d))//(c*d)
ans = n - mod_c - mod_d + mod_cd
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
n = b - a + 1
mod_c = (n + a%c - 1)//c
mod_d = (n + a%d - 1)//d
mod_cd = (n + a%(c*d) - 1)//(c*d)
ans = n - mod_c - mod_d + mod_cd
print(ans)

Submission status: Wrong Answer

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

count_c = int(b / c) - int((a-1) / c)
count_d = int(b / d) - int((a-1) / d)
lcm_cd = c * d // fractions.gcd(c, d)
count_cd = int(b / lcm_cd) - int((a-1) / lcm_cd)


print(b - a - int(count_c+count_d-count_cd) + 1)

Submission status: Wrong Answer

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

count_c = int(b / c) - int((a-1) / c)
count_d = int(b / d) - int((a-1) / d)
lcm_cd = c * d / fractions.gcd(c, d)
count_cd = int(b / lcm_cd) - int((a-1) / lcm_cd)

print(b - a - int(count_c+count_d-count_cd) + 1)

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)

C_ok = (B // C) - (A // C) + 1
D_ok = (B // D) - (A // D) + 1
C_D_ok = (B // lcm(C, D)) - (A // lcm(C, D)) + 1

print((B-A+1)-C_ok-D_ok+C_D_ok+1)

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)

C_ok = (B // C) - (A // C)
D_ok = (B // D) - (A // D)
C_D_ok = (B // lcm(C, D)) - (A // lcm(C, D))

print(B-A-C_ok-D_ok+C_D_ok+1)

Submission status: Wrong Answer

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

lcm = (C * D) // fractions.gcd(C, D)
print(B-A+1 - (B//C - A//C) - (B//D - A//D) + (B//lcm - A//lcm))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a, b, c, d = [int(i) for i in input().split()]
lcm = c * d // gcd(c, d)
divc = (b - a) // c
divd = (b - a) // d
divcd = (b - a) // lcm
print(b - a - divc - divd + divcd)

Submission status: Wrong Answer

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

x1=int(b/z)
x2=int(b/c)
x3=int(b/d)
x=x2+x3-x1
y1=int((a-1)/z)
y2=int((a-1)/c)
y3=int((a-1)/d)
y=y2+y3-y1

print(b-(a-1)-(x-y))

Submission status: Wrong Answer

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

n = 0

for i in range(a - 1, b - 1):
  if i % c != 0:
      if i % d != 0:
          n += 1

print(int(n))

Submission status: Wrong Answer

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

n = 0

for i in range(a, b):
  if (i % c != 0) and (i % d != 0):
    n += 1
    
print(int(n))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
count=0
e=(c*d)//fractions.gcd(c,d)
D=[c,d,e]
f=[]

for i in D:
  f.append((b//i)-(a//i))
print(b-a+1-f[0]-f[1]+f[2])

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    while b:
        a,b=b,a%b
        return a
    
def lcm(x,y):
    return int(x*y/gcd(x,y))

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

S=B-A+1
if(A%C==0):
    n_C=B//C-A//C+1
else:
     n_C=B//C-A//C

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

if(A%lcm(C,D)==0):
    n_CD=B//lcm(C,D)-A//lcm(C,D)+1
else:
    n_CD=B//lcm(C,D)-A//lcm(C,D)
    
print(S-n_C-n_D+n_CD)

Submission status: Wrong Answer

Solution code:
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
 
 
a,b,c,d = map(int,input().split())
l = lcm(c,d)
 
def xika(x,v1,v2,vl):
  c1 = x//v1
  c2=x//v2
  c3 = x//vl
  return c1+c2-c3

print((b-a+1)-(xika(b,c,d,l)-xika(a,c,d,l)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = (int(x) for x in input().split())
val = gcd(c,d)
lcm = (c*d) // val
div_by_c = (b // c) - (a // c) + (1 if a % c == 0 else 0)
div_by_d = (b // d) - (a // d) + (1 if a % d == 0 else 0)
div_by_lcm = (b // lcm) - (a // lcm)

print(b-a+1 - div_by_c - div_by_d + div_by_lcm)

Submission status: Wrong Answer

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

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


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

mul = 0


mul += b//c - (a-1)//c 
    
mul += b//d - (a-1)//d
    
lcm = LCM(c,d)

mul -= b//lcm - (a-1)//lcm 
    
mul = int(mul)

print(b-a+1-mul)

Submission status: Wrong Answer

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

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


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

mul = 0

if(a%c==0):
    mul += b//c - a//c 
else:
    mul += b//c - a//c
    
if(a%d==0):
    mul += b//d - a//d 
else:
    mul += b//d - a//d
    
lcm = LCM(c,d)

if(a%lcm == 0):
    mul -= b//lcm - a//lcm 
else:
    mul -= b//lcm - a//lcm 
    
mul = int(mul)

print(b-a+1-mul)

Submission status: Wrong Answer

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

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


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

mul = 0

if(a%c==0):
    mul += b//c - a//c + 1
else:
    mul += b//c - a//c
    
if(a%d==0):
    mul += b//d - a//d + 1
else:
    mul += b//d - a//d
    
lcm = LCM(c,d)

if(a%lcm == 0):
    mul -= b//lcm - a//lcm + 1
else:
    mul -= b//lcm - a//lcm 
    
mul = int(mul)

print(b-a+1-mul)

Submission status: Wrong Answer

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


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

n = b-a+1
mc = a%c-c
md = a%d-d
mcd = a%lcmcd - lcmcd

cc = int((n+mc)//c)+1
dc = int((n+md)//d)+1
cdc = int((n+mcd)//lcmcd)+1
print(n-(cc+dc-cdc))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split())
import math
from fractions import gcd
num_c = math.ceil(b/c)-1 - (math.ceil(a / c) - 1)
num_d = b // d - (math.ceil(a / d) - 1)
num_cd = b // (c * d // gcd(c, d)) - (math.ceil(a / (c * d // gcd(c, d))) - 1)
print((b - a + 1) - (num_c + num_d - num_cd))

Submission status: Wrong Answer

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

import math
from fractions import gcd
num_c = b // c - (math.ceil(a / c) - 1)
num_d = b // d - (math.ceil(a / d) - 1)
num_cd = b // (c * d // gcd(c, d)) - (math.ceil(a / (c * d // gcd(c, d))) - 1)
print((b - a + 1) - (num_c + num_d - num_cd))

Submission status: Wrong Answer

Solution code:
#a以上b以下の整数のうちcでもdでも割り切れないものの個数を求めてください
#1以上b以下の整数の条件を満たすものから1以上a-1以下のもので条件を満たすものを取り除くようにすればいい
a,b,c,d=map(int,input().split())
n=b-((b//c)+(b//d)-b//(c*d))
m=(a-1)-((a-1)//c+(a-1)//d-(a-1)//(c*d))
print(n-m)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
b += 1
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
g = c * d // gcd(c, d)
ans = b - a
ans -= b // c + b // d - b // g
ans += a // c + a // d - a // g
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
ans = b - a
print(ans)
ans -= b // c + b // d - b // (c * d)
print(ans)
ans += a // c + a // d - a // (c * d)
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
ans = b - a
ans += b // c + b // d - b // (c * d)
ans -= a // c + a // d - a // (c * d)
print(ans)

Submission status: Wrong Answer

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

for i in range(a,b,1):
    if i%c != 0 and i%d != 0:
        count += 1
print(count)

Submission status: Wrong Answer

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

for i in range(a,b,1):
    if i%c != 0:
        if i%d != 0:
            count += 1
print(count)

Submission status: Wrong Answer

Solution code:
import fractions

def solve():
    A, B, C, D = map(int, input().split())
    gcd = (C * D) // fractions.gcd(C, D)
    ans_sub = A-1 - ((A-1) // C + (A-1) // D - (A+1) // gcd)
    ans = B - (B // C + B // D - B // gcd) - ans_sub
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import fractions

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

# B以下でC, Dで割り切れるものの個数
b_c = B // C
b_d = B // D

# B以下でCでもDでも割り切れるものの個数
b_c_d = B // ((C*D)/fractions.gcd(C,D))

# A未満でC, Dで割り切れるものの個数
a_c = (A-1) // C
a_d = (A-1) // D

# A未満でCでもDでも割り切れるものの個数
a_c_d = (A-1) // ((C*D)/fractions.gcd(C,D))


count = b_c + b_d - b_c_d - (a_c + a_d - a_c_d)

ans = B-A+1 - count
print(int(ans))

Submission status: Wrong Answer

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

x = B + 1 - A

c = -(-B // C) - -(-A // C)
d = -(-B // D) - -(-A // D)
e = -(-B // (C*D)) - -(-A // (C*D))

ans = x - c - d + e

print(ans)

Submission status: Wrong Answer

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

x = B + 1 - A

c = -(-x // C)
d = -(-x // D)
e = -(-x // (C*D))

ans = x - c - d + e

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
A, B, C, D = map(int, input().split())
CD = C*D/fractions.gcd(C, D)

ac = (A-1)//C
bc = B//C
ad = (A-1)//D
bd = B//D
acd = (A-1)//CD
bcd = B//CD

print(int(B - A + 1 - ((bc - ac) + (bd - ad) - (bcd - acd))))

Submission status: Wrong Answer

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

# Aまでの数で,C,Dの倍数
a_c=(a-1)//c
a_d=(a-1)//d
# Bまでの数で,C,Dの倍数
b_c=b//c
b_d=b//d

# C,Dの最小公倍数
import fractions
cd = (c*d)/fractions.gcd(c,d) 

a_cd = (a-1)//cd
b_cd = b//cd

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

Submission status: Wrong Answer

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

import fractions

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

lcmcd=lcm(c,d)
divc=b//c-(a-1)//c
divd=b//d-(a-1)//c
divcd=b//lcmcd-(a-1)//lcmcd

print(b-a+1-divc-divd+divcd)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

    X = int(B/C) - int((A-1)/C)
    Y = int(B/D) - int((A-1)/D)
    
    lcm_CD = int(C*D/gcd(C,D))
    Z = int(B/lcm_CD) - int((A-1)/lcm_CD)

    ans = B - (A-1)
    ans -= X+Y-Z

    print(ans)

solve()

Submission status: Wrong Answer

Solution code:
A,B,C,D=list(map(int,input().split()))
x=max(C,D)
y=min(C,D)
if x%y==0:
    gcd=C*D//y
else:
    while x%y!=0:
        z=x%y
        x=y
        y=z
    gcd=C*D//z
print(B-A+1-(B//C-(A-1)//C+B//D-(A-1)//D-B//gcd-(A-1)//gcd))

Submission status: Wrong Answer

Solution code:
A,B,C,D=list(map(int,input().split()))
x=max(C,D)
y=min(C,D)
if x%y==0:
    gcd=C*D//y
else:
    while x%y!=0:
        z=x%y
        x=y
        y=z
    gcd=C*D//z
print(B-A+1)

Submission status: Wrong Answer

Solution code:
from fractions import gcd


def lcm(p, q):
    return p * q // gcd(p, q)


def anti_division():
    a, b, c, d = map(int, input().split())
    numbers = b - a + 1
    cd_gcd = lcm(c, d)
    a_multiples = [a // min(c, d), a // max(c, d)]
    b_multiples = [b // min(c, d), b // max(c, d)]
    gcd_multiples = [a // cd_gcd, b // cd_gcd]
    ans = numbers - ((b_multiples[1] - a_multiples[1]) + (b_multiples[0] - a_multiples[0]) - (
                gcd_multiples[1] - gcd_multiples[0]))
    print(ans)


if __name__ == '__main__':
    anti_division()

Submission status: Wrong Answer

Solution code:
from fractions import gcd


def lcm(p, q):
    return p * q // gcd(p, q)


def anti_division():
    a, b, c, d = map(int, input().split())
    numbers = b - a + 1
    cd_gcd = lcm(c, d)
    a_multiples = [a // c, a // d]
    b_multiples = [b // c, b // d]
    gcd_multiples = [a // cd_gcd, b // cd_gcd]
    ans = numbers - ((b_multiples[1] - a_multiples[1]) + (b_multiples[0] - a_multiples[0]) - (
                gcd_multiples[1] - gcd_multiples[0]))
    print(ans)


if __name__ == '__main__':
    anti_division()

Submission status: Wrong Answer

Solution code:
from fractions import gcd


def lcm(p, q):
    return p * q // gcd(p, q)

def anti_division():
    a, b, c, d = map(int, input().split())
    numbers = b - a + 1
    cd_gcd = lcm(c, d)
    a_multiples = [a//c, a//d]
    b_multiples = [b//c, b//d]
    gcd_multiples = [a//cd_gcd, b//cd_gcd]
    ans = numbers - ((b_multiples[1]-a_multiples[1]) + (b_multiples[0]-a_multiples[0]) - (gcd_multiples[1]-gcd_multiples[0]))
    print(ans)

if __name__ == '__main__':
    anti_division()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def gcd(m,n):
	while n!=0:
		m,n = n,m % n
	return m

def lcm(m,n):
	return m * n // gcd(m,n)

CD = lcm(C,D)

supC = B // C
supD = B // D
supCD = B // (CD)

infC = A // C
infD = A // D
infCD = A // (CD)

num = B - A + 1
num = num - supC - supD + supCD + infC + infD - infCD
print(num)

Submission status: Wrong Answer

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

supC = B // C
supD = B // D
supCD = B // (C * D)

infC = A // C
infD = A // D
infCD = A // (C * D)

num = B - A + 1
num = num - supC - supD + supCD + infC + infD - infCD
print(num)

Submission status: Wrong Answer

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

cList = []

dList = []

numList = []

supC = (B // C)
infC = (A // C)

supD = (B // D)
infD = (A // D)

for i in range(infC,supC+1):
	cList.append(i * C)

for i in range(infD,supD+1):
	dList.append(i * D)
	
for i in range(A,B+1):
	if i in cList or dList is False:
		numList.append(i)
	

print(len(numList))

Submission status: Wrong Answer

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

cList = []

dList = []

numList = []

supC = (B // C)
infC = (A // C) + 1

supD = (B // D)
infD = (A // D) + 1

for i in range(A,B+1):
	numList.append(i)
	
for i in range(infC,supC+1):
	cList.append(i * C)
	
for i in range(infD,supD+1):
	dList.append(i * D)
	
numList = len(set(numList) - set(cList) - set(dList))

print(numList)

Submission status: Wrong Answer

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

L = []

counter = 0

for i in range(A,B):
	L.append(i)
	
for i in range(0,len(L)-1):
	if L[i] % C and L[i] % D != 0:
		counter += 1
		
print(counter)

Submission status: Wrong Answer

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

L = []

counter = 0

for i in range(A,B+1):
	L.append(i)
	
for i in range(0,len(L)-1):
	if L[i] % C and L[i] % D != 0:
		counter += 1
		
print(counter)

Submission status: Wrong Answer

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


#1~a
a_count = (a-1)//c + (a-1)//d - (a-1)//(c*d)
b_count = b//c + b//d - b//(c*d)
answer = b_count - a_count
print(b - a + 1 - answer)

Submission status: Wrong Answer

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

# A以上B以下の整数のうち、(CまたはDの倍数)でないものの個数を求める
# CまたはDの倍数の個数 = Cの倍数の個数+Dの倍数の個数-CとDの最小公倍数の倍数の個数
# 途中式でfloatが出てこないようにしないと大きな数の計算時に結果がズレるので注意

def n_multiple(x):
    return B//x - math.ceil(A/x) + 1

def lcd(x,y):
    while y>0:
        x,y = y, x%y
    return(x)

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

print(int((B-A+1) - (n_multiple(C)+n_multiple(D)-n_multiple(gcd(C,D)))))

Submission status: Wrong Answer

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

# A以上B以下の整数のうち、(CまたはDの倍数)でないものの個数を求める
# CまたはDの倍数の個数 = Cの倍数の個数+Dの倍数の個数-CとDの最小公倍数の倍数の個数

def n_multiple(x):
    return B//x - math.ceil(A/x) + 1

def lcd(x,y):
    while y>0:
        x,y = y, x%y
    return(x)

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

print(int((B-A+1) - (n_multiple(C)+n_multiple(D)-n_multiple(gcd(C,D)))))

Submission status: Wrong Answer

Solution code:
def getDivisableCount(min_bound, max_bound, div):
    return int(max_bound / div) - int((min_bound - 1) / div)

def LCM(a, b):
    return a * b / GCD(a, b)

def GCD(a, b):
    if a > b:
        a, b = b, a
    while b % a != 0:
        tmp = b % a
        b = a
        a = tmp
    return a

if __name__ == '__main__':
    A, B, C, D = [int(i) for i in input().split()]
    ret = (B - A + 1) - getDivisableCount(A, B, C) - getDivisableCount(A, B, D) + getDivisableCount(A, B, LCM(C, D))
    print(ret)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def gcd(x, y):
    if y > x:
        return gcd(y, x)
    if x % y == 0:
        return y
    return gcd(y, x%y)

cd = int(c * d / gcd(c, d))

b_div = b - int(b/c) - int(b/d) + int(b/cd)
a_div = a-1 - int((a-1)/c) - int((a-1)/d) + int((a-1)/cd)

print(b_div - a_div)

Submission status: Wrong Answer

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

def gcd(x, y):
    if y > x:
        return gcd(y, x)
    if x % y == 0:
        return y
    return gcd(y, x%y)

cd = int(c * d / gcd(c, d))

def f(x, y, div):
    return int(max(x, y) / div) - int((min(x, y) - 1) / div)


print(b-a+1 - f(a, b, c) - f(a, b, d) + f(a, b, cd))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split())
cc = b//c - a//c
dd = b//d - a//d
cd = b//(c*d) - a//(c*d)

print((b-a+1) + cd - cc -dd)

Submission status: Wrong Answer

Solution code:
import math
import fractions


def calc(x):
    aa = math.ceil(a/x)*x
    bb = math.floor(b/x)*x
    return int((bb - aa) // x + 1)


a, b, c, d = map(int, input().split())
cd = c * d / fractions.gcd(c, d)
# print(b - a + 1, calc(cd), calc(c), calc(d))
print(int(b - a + 1 + calc(cd) - calc(c) - calc(d)))

Submission status: Wrong Answer

Solution code:
import fractions as fr
a, b, c, d = map(int, input().split())
lcm = (c*d)//fr.gcd(c, d)
ans = (b-a)//c + (b-a)//d - (b-a)//lcm


if a % c == 0:
    ans += 1
if b % c == 0:
    ans += 1
if (b-a) % c == 0:
    ans -=1

if a % d == 0:
    ans += 1
if b % d == 0:
    ans += 1
if (b-a) % d == 0:
    ans -= 1

if a % lcm == 0:
    ans -= 1
if b % lcm == 0:
    ans -= 1
if (b-a) % lcm == 0:
    ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions as fr
a, b, c, d = map(int, input().split())
lcm = (c*d)//fr.gcd(c, d)
ans = (b-a)//c + (b-a)//d - (b-a)//lcm
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
A,B,C,D = map(int,input().split())
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a
E = C * D // gcd(C,D)

dif = B - A + 1
rc = math.floor(B/C) - math.ceil(A/C) + 1
rd = math.floor(B/D) - math.ceil(A/D) + 1
re = math.floor(B/E) - math.ceil(A/E) + 1
x = dif - rc - rd + re
print(x)

Submission status: Wrong Answer

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

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

def calc(div):
  return floor(B / div) - ceil((A - 1) / div)

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

Submission status: Wrong Answer

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

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

def calc(div):
  return floor(B / div) - ceil(A / div) + 1

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

Submission status: Wrong Answer

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

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

def calc(div):
  return floor(B / div) - ceil(A / div) + 1

print((B - A + 1) - (calc(C) + calc(D) - calc(C * D / gcd(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)

big=0
small = 0

big += b//c
big += b//d
big -= b//lcm

small += (a-1)//c
small += (a-1)//d
small -= (a-1)//lcm

print(int((b-a+1)-(big - small)))

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
def f(s,x,y):
  return s-s//x-s//y+s//(x*y)
print(f(b,c,d)-f(a-1,c,d))

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
a_0=a//c
a_1=a//d
a_2=a//(c*d)
n=a_0+a_1-a_2
b_0=b//c
b_1=b//d
b_2=b//(c*d)
m=b_0+b_1-b_2
print(m-n)

Submission status: Wrong Answer

Solution code:
import math
import fractions


def calc(x):
    aa = math.ceil(a/x)*x
    bb = math.floor(b/x)*x
    return int((bb - aa) // x + 1)


a, b, c, d = map(int, input().split())
cd = c * d / fractions.gcd(c, d)
print(int(b - a + 1 + calc(cd) - calc(c) - calc(d)))

Submission status: Wrong Answer

Solution code:
import math
import fractions


def calc(x):
    aa = math.ceil(a/x)*x
    bb = math.floor(b/x)*x
    return int((bb - aa) // x + 1)


a, b, c, d = map(int, input().split())
cd = c * d / fractions.gcd(c, d)
print(calc(c), calc(d), calc(cd))
print(int(b - a + 1 + calc(cd) - calc(c) - calc(d)))

Submission status: Wrong Answer

Solution code:
import math

def gcd(x,y):
	while y:
		x,y = y,x % y
	return x


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

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

c_mod = a % c
d_mod = a % c
cd_mod = a % cd

if b >= c:
	ans += math.ceil( (b - a + 1) / c )
if b >= d:
	ans += math.ceil( (b - a + 1) / d )
if b >= cd:
	ans -= math.ceil( (b - a + 1) / cd )

if a == 1:
	print(b-a+2-ans)
else:
	print(b-a+1-ans)

Submission status: Wrong Answer

Solution code:
import math

def gcd(x,y):
	while y:
		x,y = y,x % y
	return x


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

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

c_mod = a % c
d_mod = a % c
cd_mod = a % cd

ans += math.ceil( (b - a + 1) / c )
ans += math.ceil( (b - a + 1) / d )
ans -= math.ceil( (b - a + 1) / cd )

print(b-a+1-ans)

Submission status: Wrong Answer

Solution code:
import fractions as math
a,b,c,d = map(int,input().split())
"""
aからbまでの倍数を求めるのではなく、
0からa-1,0からbまでの２つに分けてそれぞれ出して差で求める。
"""
f = 0
a = a-1 #0からb迄を求めるときにaはもう使わないので変えちゃっていい
lcm = (c*d/math.gcd(c,d))
c = b//c - a//c
d = b//d - a//d
for i in range(int(a//lcm)-2,int(b//lcm)+2):
    if a < i*lcm <= b:
        f = 1
        break
if f:
    cd = b//lcm - a//lcm
else:
    cd = 0
#求めるのは割り切れる数ではなく割り切れない数
print(b-a-int(c+d-cd))

Submission status: Wrong Answer

Solution code:
import fractions as math
a,b,c,d = map(int,input().split())
"""
aからbまでの倍数を求めるのではなく、
0からa-1,0からbまでの２つに分けてそれぞれ出して差で求める。
"""

a = a-1 #0からb迄を求めるときにaはもう使わないので変えちゃっていい
lcm = (c*d/math.gcd(c,d))
c = b//c - a//c
d = b//d - a//d
cd = b//lcm - a//lcm
#求めるのは割り切れる数ではなく割り切れない数
print(b-a-int(c+d-cd))

Submission status: Wrong Answer

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

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

total = b+1 - ((b+1)//c + (b+1)//d - (b+1)//lcm)
total_del = a - (a//c + a//d - a//lcm)

print(total - total_del)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from math import ceil
def div(n,a,b):
    m = b//n-ceil(a/n)+1
    #print(m)
    return max(m,0)
a,b,c,d = map(int,input().split())
e = c*d//gcd(c,d)
print(b-a+1-(div(c,a,b) + div(d,a,b) - div(e,a,b)))