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())
c_=0
d_=0
n=0
if a%c!=0 and b>c:
    c_= a+c-a%c #12
    n+=1
elif b<c:
    c_= b
else:
    c_ = a
    n+=1
if a%d!=0 and b>d:
    d_= a+d-a%d #16
    n+=1
elif b<d:
    d_= b
else:
    d_ = a
    n+=1
r = max(c,d)%min(c,d)
b_=min(c,d)
while r!=0:
    a_= b_
    b_=r
    r=a_%b_
e = int(c*d/b_)
if (a%c!=0 or a%d!=0) and b>e:
    e_= a+e-a%e #48
    n-=1
elif b<e:
    e_= b
else:
    e_ = a
    n-=1
n += (b-c_)//c+(b-d_)//d-(b-e_)//(c*d)
print(1+b-a-n)

Submission status: Wrong Answer

Solution code:
import math

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
  
def lcm(x, y):
  return (x * y) // gcd(x, y)
  
a, b, c, d = (int(i) for i in input().split())  

n = b - a + 1
ans = n -(math.ceil(n/c) + math.ceil(n/d) - math.ceil(n/lcm(c, d)))
print(ans)

Submission status: Wrong Answer

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

n = b - a + 1
ans = n -(math.ceil(n/c) + math.ceil(n/d) - math.ceil(n/(c * d)))
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
c_=0
d_=0
n=0
if a%c!=0:
    c_= a+c-a%c 
else:
    c_ = a
if a%d!=0:
    d_= a+d-a%d 
else:
    d_ = a
if (a%c!=0 or a%d!=0) and a>c*d:
    e_= a+c*d-a%(c*d) 
else:
    e_ = a
n += (b-c_)//c+(b-d_)//d-(b-e_)//(c*d)
print(b-a-n)

Submission status: Wrong Answer

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

n = b - a + 1
print(n -(n//c + n//d - n//(c * d)))

Submission status: Wrong Answer

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

A=x[0]
B=x[1]
C=x[2]
D=x[3]


C1=B//C
D1=B//D

C2=(A-1)//C
D2=(A-1)//D


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

lcm=C*D / gcd(C,D)
#print(lcm)

lcm1=B//lcm
lcm2=(A-1)//lcm
#print(lcm1,lcm2)

ans=B-A-C1+C2-D1+D2+lcm1-lcm2+1
print('{:.18g}'.format(ans))

Submission status: Wrong Answer

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

A=x[0]
B=x[1]
C=x[2]
D=x[3]


C1=B//C
D1=B//D

C2=(A-1)//C
D2=(A-1)//D


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

lcm=C*D / gcd(C,D)
#print(lcm)

lcm1=B//lcm
lcm2=(A-1)//lcm
#print(lcm1,lcm2)

ans=B-A-C1+C2-D1+D2+lcm1-lcm2+1

print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
def gcd(x,y):
    if x==0:
        return y
    else:
        return gcd(y%x,x)
def lcm(x,y):
    return x*y/gcd(x,y)

e=lcm(c,d)
ans=0
ans=int(b/c)-int((a-1)/c)+int(b/d)-int((a-1)/d)
ans-=int(b/e)-int((a-1)/e)
print(b-a+1-ans)

Submission status: Wrong Answer

Solution code:
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 += 1
print(count)

Submission status: Wrong Answer

Solution code:
from math import ceil
from math import floor

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())
CD = lcm(C, D)

divC = (B+1)//C - A//C
divD = (B+1)//D - A//D
divCD = (B+1)//CD - A//CD

cnt = B-A+1 - divC - divD + divCD
print(cnt)

Submission status: Wrong Answer

Solution code:
from math import ceil
from math import floor

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())
CD = lcm(C, D)
sC = ceil(A/C)
gC = floor(B/C)
sD = ceil(A/D)
gD = floor(B/D)
sCD = ceil(A/CD)
gCD = floor(B/CD)

cnt = B - A + 1 - ((gC - sC + 1) + (gD - sD + 1) - (gCD - sCD + 1))
print(cnt)

Submission status: Wrong Answer

Solution code:
import fractions
x = input().split()
a,b,c,d = int(x[0]),int(x[1]),int(x[2]),int(x[3])

cn=0
if a%c==0:
    cn+=1
cn+=int(b/c)-int(a/c)
dn=0
if a%d==0:
    dn+=1
dn+=int(b/d)-int(a/d)

cdn=0
cd = int(c*d/fractions.gcd(c,d))
if a%cd==0:
    cdn+=1
cdn+=int(b/cd)-int(a/cd)

print((b-a+1)-(cn+dn-cdn))

Submission status: Wrong Answer

Solution code:
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))
 
 
f=(a-c)//c+1
g=b//c
h=(a-d)//d+1
k=b//d
l=(a-e)//e+1
m=b//e
x=b-a+1
y=g-f+1
z=k-h+1
w=m-l+1
print(x-y-z+w)

Submission status: Wrong Answer

Solution code:
import fractions
x = input().split()
a,b,c,d = int(x[0]),int(x[1]),int(x[2]),int(x[3])

cn=0
if a%c==0:
    cn+=1
cn+=int(b/c)-int(a/c)
dn=0
if a%d==0:
    dn+=1
dn+=int(b/d)-int(a/d)

cdn=0
cd = c*d/fractions.gcd(c,d)
if a%cd==0:
    cdn+=1
cdn+=int(b/cd)-int(a/cd)

print((b-a+1)-(cn+dn-cdn))

Submission status: Wrong Answer

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

A=x[0]
B=x[1]
C=x[2]
D=x[3]
count=0


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

print(count)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

Submission status: Wrong Answer

Solution code:
#整数 A,B,C,D が与えられます。A 以上 B 以下の整数のうち、C でも D でも割り切れないものの個数を求めてください。

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

for i in range(A-1, B-1):
    num = i
    if not num%C == 0 and not num%D == 0:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y)

def num(n, c, d):
    g = gcd(c, d)
    l = c / g * d
    return n - (n / c) - (n / d) + (n / l) 
    #n以下の整数のうち，cでもdでも割り切れない個数

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

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 = list(map(int, input().split()))

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

Submission status: Wrong Answer

Solution code:
import fractions
import math

def cal(X, A, B):
  X_min, X_max = math.ceil(A/X), math.floor(B/X)
  return X_max - X_min + 1

def main():
  A, B, C, D = map(int, input().split())
  num_all = B-A+1
  C_min = min(C,D)
  D_max = max(C,D)
  CD = (C*D)//fractions.gcd(C,D)
  ans_list = []
  for X in [C_min, D_max, CD]:
    num_leave = cal(X, A, B)
    ans_list.append(num_leave)
  print(num_all - (ans_list[0]+ans_list[1]-ans_list[2]))
  
main()

Submission status: Wrong Answer

Solution code:
import fractions
import math

def cal(X, A, B):
  X_min, X_max = math.ceil(A/X), math.floor(B/X)
  if X_max == 0: return 0
  return X_max - X_min + 1


def main():
  A, B, C, D = map(int, input().split())
  num_all = B-A+1
  C_min = min(C,D)
  D_max = max(C,D)
  CD = (C*D)//fractions.gcd(C,D)
  ans_list = []
  for X in [C_min, D_max, CD]:
    num_leave = cal(X, A, B)
    ans_list.append(num_leave)
  print(num_all - (ans_list[0]+ans_list[1]-ans_list[2]))
  
main()

Submission status: Wrong Answer

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

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

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

E=lcm(C,D)

Cmin=A-A%C
Cmax=B-B%C
Dmin=A-A%D
Dmax=B-B%D
Emin=A-A%E
Emax=B-B%E

num = ((Cmax-Cmin)/C)+((Dmax-Dmin)/D)-((Emax-Emin)/E)

print(int(B-A+1-num))

Submission status: Wrong Answer

Solution code:
import fractions
import math


def main():
    min_num, max_num, C, D = map(int, input().split())
    diff_C = aida_num(max_num, min_num, C)
    diff_D = aida_num(max_num, min_num, D)
    diff_CD = aida_num(max_num, min_num, lcm(C, D))

    # print(diff_C, diff_D, diff_CD)

    diff = diff_C + diff_D - diff_CD
    print(max_num - min_num + 1 - diff)


def aida_num(max_num: int, min_num: int, target: int):
    return math.floor(max_num / target) - math.ceil(min_num / target) + 1


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

large_c = (b + 1) // c
large_d = (b + 1) // d
large_cd = (b + 1) // (c * d)
large = large_c + large_d - large_cd

small_c = (a - 1) // c
small_d = (a - 1) // d
small_cd = (a - 1) // (c * d)
small = small_c + small_d - small_cd

if b % c == 0:
    b += 1
elif b % d == 0:
    b += 1
print((b - (a - 1)) - (large - small))

Submission status: Wrong Answer

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

large_c = (b + 1) // c
large_d = (b + 1) // d
large_cd = (b + 1) // (c * d)
large = large_c + large_d - large_cd

small_c = (a - 1) // c
small_d = (a - 1) // d
small_cd = (a - 1) // (c * d)
small = small_c + small_d - small_cd

print(((b + 1) - (a - 1)) - (large - small))

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
ans=0
for a in range(b):
  if a%c!=0 and a%d!=0:
    ans+=1
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
ans=0
for a in range(b):
  if a%c!=0 or a%d!=0:
    ans+=1
print(ans)

Submission status: Wrong Answer

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

one_to_b = B - ((B // C) + (B // D) - (B // (C * D)))
one_to_a = A - 1 - ((((A - 1) // C) +
                     ((A - 1) // D) -
                     (A - 1) // (C * D)))

print(one_to_b - one_to_a)

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d=map(int,input().split())
k=fractions.gcd(c,d)
t=c*d//k
coub=b//c
coua=a//c
cob=b//d
coa=a//d
cb=b//t
ca=a//t
print(b-a+1-coub-cob-ca+coua+coa+cb)

Submission status: Wrong Answer

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

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

g = gcd(C, D) if C < D else gcd(D, C)
ansB = B-B/C-B/D+B/(C*D/g)
ansA = A - 1 - (A-1)/C - (A-1)/D + (A-1)/(C*D/g)
print(ansB-ansA)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,(input().split(" ")))
count = int(0)
for i in range(A,B):
    if(i % C and i % D):
        count += 1

print(count)

Submission status: Wrong Answer

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

target_numbers = range(A, B)
results = [n for n in target_numbers if (n % C and n % D)]

print(len(results))

Submission status: Wrong Answer

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

y = b // d
w = b //(c*d)
z = (a - 1) // d
v = (a - 1) // c
h = (a - 1) // (c*d)
print((b - x - y + w) - ((a-1) - z - v + h))
print(x,y,v,z)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
x = b // c
y = b // d
z = (a - 1) // b
v = (a - 1) // c
print((b - x - y) - ((a-1) - z - v))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
n = B-A+1
c1 = n//C
d1 = n//D
cd = n//(C*D)
if ((A+c1*C-1)%C + (B-(A+c1*C-1))) // C == 1:
    c1 += 1
if ((A+d1*D-1)%D + (B-(A+d1*D-1))) // D == 1:
    d1 += 1
if ((A+cd*C*D-1)%(C*D) + (B-(A+cd*C*D-1))) // (C*D) == 1:
    cd += 1
print(n-(c1+d1-cd))

Submission status: Wrong Answer

Solution code:
import fractions

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

gcd = fractions.gcd(C, D)

lcm = C * D / gcd

ac = A/C
bc = B/C
ad = A/D
bd = B/D
acd = A/lcm
bcd = B/lcm

if A%C != 0:
    ac = int(ac) + 1
if B%C != 0:
    bc = int(bc)
if A%D != 0:
    ad = int(ad) + 1
if B%D != 0:
    bd = int(bd)
if A%lcm != 0:
    acd = int(acd) + 1
if B%lcm != 0:
    bcd = int(bcd)

    
c_n = bc - ac + 1
d_n = bd - ad + 1
cd_n = bcd - acd + 1

ans = B - A + 1 - c_n - d_n + cd_n
print(int(ans))

Submission status: Wrong Answer

Solution code:
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 += 1
print(count)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
ans = 0
for i in range(A,B):
  if i%C != 0:
    if i%D != 0:
      ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

inputs = [int(i) for i in input().split()]

counter = 0

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

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

l = lcm(c, d)

c1 = b // c
c2 = (a-1) // c
c3 = c1 - c2

d1 = b // d
d2 = (a-1) // d
d3 = d1 - d2

l1 = b // l

ans = (b-a+1) - (c3 + d3 - l1)
print(ans)

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
g = gcd(c,d)
l = c*d/g
ans = (b-a+1) - (int(b/c)-int(a/c)+1) - (int(b/d)-int(a/d)+1) + (int(b/l)-int(a/l)+1) + 1
print(ans)

Submission status: Wrong Answer

Solution code:
ABCD = input().split()
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])

def gcd(x,y):
    while y != 0:
        z = x%y
        if z == 0:
            return y
        x, y = y, x%y

g = gcd(C,D)
l = C*D/g
count = (B-A+1)-(int(B/C)+int(B/D)-int(B/l)-(int(A/C)+int(A/D)-int(A/l)))
print(count)

Submission status: Wrong Answer

Solution code:
ABCD = input().split()
A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])

count = (B-A+1)-(int(B/C)+int(B/D)-int(B/(C*D))-(int(A/C)+int(A/D)-int(A/(C*D))))
print(count)

Submission status: Wrong Answer

Solution code:
NL = input().split()
N = int(NL[0])
L = int(NL[1])
apple = []
apple_abs = []
sum = 0
for i in range(1,N+1):
  apple.append(L+i-1)
  apple_abs.append(abs(L+i-1))

apple_min = min(apple_abs)

for i in apple:
  if abs(i) == apple_min:
    continue
  sum += i
print(sum)

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 = map(int, input().split())
a = a - 1
e = b - int(b / c) - int(b / d) + int(b / lcm(c, d))
f = a - int(a / c) - int(a / d) + int(a / lcm(c, d))
print(e - f)

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)


ans = B - A + 1
ans -= (B // C + B // D) - (A // C + A // D)
E = lcm(C, D)
ans += B // E - A // E

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 = map(int, input().split())
e = b - int(b / c) - int(b / d) + int(b / lcm(c, d))
f = (a - 1) - int((a - 1) / c) - int((a - 1) / d) + int((a - 1) / lcm(c, d))
if e - f >= 0:
    print(e - f)
else:
    print(0)

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 = map(int, input().split())
e = b - int(b / c) - int(b / d) + int(b / lcm(c, d))
f = (a - 1) - int((a - 1) / c) - int((a - 1) / d) + int((a - 1) / lcm(c, d))
print(e - f)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b
 
def main():
    A,B,C,D=input().split()
    A=int(A)
    B=int(B)
    C=int(C)
    D=int(D)
    if A%C!=0:
        C_min=A-A%C+C
    else:
        C_min=A
    C_max=B-B%C
    if A%D!=0:
        D_min=A-A%D+D
    else:
        D_min=A
    D_max=B-B%D
    if A%(C*D/gcd(C,D))!=0:
        CD_min=A-A%(C*D/gcd(C,D))+(C*D/gcd(C,D))
    else:
        CD_min=A
    CD_max=B-B%(C*D/gcd(C,D))
    C_sum=(C_max-C_min)/C+1
    D_sum=(D_max-D_min)/D+1
    CD_sum=(CD_max-CD_min)/(C*D/gcd(C,D))+1
    sum= B-A+1-(C_sum+D_sum-CD_sum)
    return sum
sum=main()
print(int(sum))

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b
 
def main():
    A,B,C,D=input().split()
    A=int(A)
    B=int(B)
    C=int(C)
    D=int(D)
    if A%C!=0:
        C_min=A-A%C+C
    else:
        C_min=A
    C_max=B-B%C
    if A%D!=0:
        D_min=A-A%D+D
    else:
        D_min=A
    D_max=B-B%D
    if A%(C*D/gcd(C,D))!=0:
        CD_min=A-A%(C*D/gcd(C,D))+(C*D/gcd(C,D))
    else:
        CD_min=A
    CD_max=B-B%(C*D/gcd(C,D))
    C_sum=(C_max-C_min)/C+1
    D_sum=(D_max-D_min)/D+1
    CD_sum=(CD_max-CD_min)/(C*D/gcd(C,D))+1
    sum= B-A+1-(C_sum+D_sum-CD_sum)
    return sum
sum=main()
sum_down=sum-sum%(10**8)
if (int(sum_down/10**8))!=0:
    print(str(int(sum_down/10**8))+str(int(sum%(10**8))))
else:
    print(str(int(sum%(10**8))))

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b
def main():
    A,B,C,D=map(int,input().split())
    if A%C!=0:
        C_min=A-A%C+C
    else:
        C_min=A
    C_max=B-B%C
    if A%D!=0:
        D_min=A-A%D+D
    else:
        D_min=A
    D_max=B-B%D
    mod=C*D/gcd(C,D)
    if A%mod!=0:
        CD_min=A-A%mod+mod
    else:
        CD_min=A
    CD_max=B-B%mod
    C_sum=(C_max-C_min)/C
    D_sum=(D_max-D_min)/D
    CD_sum=(CD_max-CD_min)/mod
    sum= B-A+1-int(C_sum+D_sum-CD_sum+1)
    return sum
print(int(main()))

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b
def main():
    A,B,C,D=map(int,input().split())
    if A%C!=0:
        C_min=A-A%C+C
    else:
        C_min=A
    C_max=B-B%C
    if A%D!=0:
        D_min=A-A%D+D
    else:
        D_min=A
    D_max=B-B%D
    mod=C*D/gcd(C,D)
    if A%mod!=0:
        CD_min=A-A%mod+mod
    else:
        CD_min=A
    CD_max=B-B%mod
    C_sum=(C_max-C_min)/C
    D_sum=(D_max-D_min)/D
    CD_sum=(CD_max-CD_min)/mod
    sum= B-A+1-int(C_sum+D_sum-CD_sum+1)
    return sum
print(main())

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b
def main():
    A,B,C,D=map(int,input().split())
    if A%C!=0:
        C_min=A-A%C+C
    else:
        C_min=A
    C_max=B-B%C
    if A%D!=0:
        D_min=A-A%D+D
    else:
        D_min=A
    D_max=B-B%D
    mod=C*D/gcd(C,D)
    if A%mod!=0:
        CD_min=A-A%mod+mod
    else:
        CD_min=A
    CD_max=B-B%mod
    C_sum=(C_max-C_min)/C
    D_sum=(D_max-D_min)/D
    CD_sum=(CD_max-CD_min)/mod
    sum= B-A+1-int(C_sum+D_sum-CD_sum-1)
    return sum
print(main())

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b
def main():
    A,B,C,D=map(int,input().split())
    if A%C!=0:
        C_min=A-A%C+C
    else:
        C_min=A
    C_max=B-B%C
    if A%D!=0:
        D_min=A-A%D+D
    else:
        D_min=A
    D_max=B-B%D
    mod=C*D/gcd(C,D)
    if A%mod!=0:
        CD_min=A-A%mod+mod
    else:
        CD_min=A
    CD_max=B-B%mod
    C_sum=(C_max-C_min)/C
    D_sum=(D_max-D_min)/D
    CD_sum=(CD_max-CD_min)/mod
    sum= B-A+1-int(C_sum+D_sum-CD_sum)
    return sum
print(main())

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b
def main():
    A,B,C,D=map(int,input().split())
    if A%C!=0:
        C_min=A-A%C+C
    else:
        C_min=A
    C_max=B-B%C
    if A%D!=0:
        D_min=A-A%D+D
    else:
        D_min=A
    D_max=B-B%D
    mod=C*D/gcd(C,D)
    if A%mod!=0:
        CD_min=A-A%mod+mod
    else:
        CD_min=A
    CD_max=B-B%mod
    C_sum=(C_max-C_min)/C+1
    D_sum=(D_max-D_min)/D+1
    CD_sum=(CD_max-CD_min)/mod+1
    sum= B-A+1-int(C_sum+D_sum-CD_sum)
    return sum
print(main())

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b
def main():
    A,B,C,D=map(int,input().split())
    if A%C!=0:
        C_min=A-A%C+C
    else:
        C_min=A
    C_max=B-B%C
    if A%D!=0:
        D_min=A-A%D+D
    else:
        D_min=A
    D_max=B-B%D
    if A%(C*D/gcd(C,D))!=0:
        CD_min=A-A%(C*D/gcd(C,D))+(C*D/gcd(C,D))
    else:
        CD_min=A
    CD_max=B-B%(C*D/gcd(C,D))
    C_sum=(C_max-C_min)/C+1
    D_sum=(D_max-D_min)/D+1
    CD_sum=(CD_max-CD_min)/(C*D/gcd(C,D))+1
    sum= B-A+1-int(C_sum+D_sum-CD_sum)
    return sum
print(main())

Submission status: Wrong Answer

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

if c > d:
    tem = c
    c = d
    d = tem
sa = b - a + 1
ans = sa - (sa // c + sa // d - sa // (c * d))

if (a % c + a % d) > c:
    ans -= 1
print(ans)

Submission status: Wrong Answer

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

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

betweenAandB = B-A+1

cA = math.ceil(A/C)
cB = math.floor(B/C)
cDiv = cB - cA + 1

dA = math.ceil(A/D)
dB = math.floor(B/D)
dDiv = dB - dA + 1

GCD = gcd(C,D)
LCM = C*D//GCD

lcmA = math.ceil(A/LCM)
lcmB = math.floor(B/LCM)
lcmDiv = lcmB - lcmA + 1

ans = betweenAandB - cDiv - dDiv + lcmDiv
print(ans)

Submission status: Wrong Answer

Solution code:
import math
input = list(map(int,input().split()))
A = input[0]
B = input[1]
C = input[2]
D = input[3]

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

betweenAandB = B-A+1

cA = math.ceil(A/C)
cB = math.floor(B/C)
cDiv = cB - cA + 1

dA = math.ceil(A/D)
dB = math.floor(B/D)
dDiv = dB - dA + 1

GCD = gcd(C,D)
LCM = C*D/GCD

lcmA = math.ceil(A/LCM)
lcmB = math.floor(B/LCM)
lcmDiv = lcmB - lcmA + 1

ans = betweenAandB - cDiv - dDiv + lcmDiv
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import*
 
A,B,C,D=map(int,input().split())
A=A-1
G=gcd(C,D)
MM=(B//C)+(B//D)-B//(C*D/G)
NN=(A//C)+(A//D)-A//(C*D/G)
GG=(B-MM)-(A-NN)
print(GG)

Submission status: Wrong Answer

Solution code:
from fractions import*
 
A,B,C,D=map(int,input().split())
A=A-1
G=(gcd(C,D))
MM=((B//C)+(B//D)-(B//(C*D/G)))
NN=((A//C)+(A//D)-(A//(C*D/G)))
GG=((B-MM)-(A-NN)) 
print((GG))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
a,b,c,d=map(int,input().split())
ans=b-a+1-(b//c-(a-1)//c+b//d-(a-1)//d)
c1,d1=c,d
if c1<d1:
    c1,d1=d1,c1
while c1%d1!=0:
    c1,d1=d1,c1%d1
d1=c*d/d1
ans=ans+(b//d1-(a-1)//d1)
print(int(ans))

Submission status: Wrong Answer

Solution code:
import fractions


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


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

cntC = b // c - (a - 1) // c
cntD = b // d - (a - 1) // d
cntCandD = b // (c * d) - (a - 1) // lcm(c, d)

# print(cntC, cntD, cntCandD)
print(b - a + 1 - cntC - cntD + cntCandD)

Submission status: Wrong Answer

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

cntC = b // c - (a - 1) // c
cntD = b // d - (a - 1) // d
cntCandD = b // (c * d) - (a - 1) // (c * d)

# print(cntC, cntD, cntCandD)
print(b - (a - 1) - cntC - cntD + cntCandD)

Submission status: Wrong Answer

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

cntC = b // c - (a - 1) // c
cntD = b // d - (a - 1) // d
cntCandD = b // (c * d) - (a - 1) // (c * d)

print(cntC, cntD, cntCandD)
print(b - (a - 1) - cntC - cntD + cntCandD)

Submission status: Wrong Answer

Solution code:
import math

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

cntC = math.ceil((b - a) / c)
cntD = math.ceil((b - a) / d)
cntCandD = math.ceil((b - a) / (c * d))

# print(cntC, cntD, cntCandD)
print((b - a + 1) - (cntC + cntD - cntCandD))

Submission status: Wrong Answer

Solution code:
def f(X,Y):
    return X//Y

A,B,C,D = map(int, input().split())
X = B-A+1
if (C>D):
    x = C
    y = D
else:
    y = C
    x = D

r = x % y
while(r!=0):
    x = y
    y = r
    r = x % y

print("%d" % (X - f(X, C) - f(X, D) + f(X, C*D//y)))

Submission status: Wrong Answer

Solution code:
def f(X,Y):
    return X//Y

A,B,C,D = map(int, input().split())
X = B-A+1
if (C>D):
    x = C
    y = D
else:
    y = C
    x = D

r = x % y
while(r!=0):
    x = y
    y = r
    r = x % y

print(C*D/y)
print("%d" % (X - f(X, C) - f(X, D) + f(X, C*D//y)))

Submission status: Wrong Answer

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

if (C>D):
    x = C
    y = D
else:
    y = C
    x = D

r = x % y
while(r!=0):
    y = x
    x = r
    r = x % y

print("%d" % (X - ((X // C) + (X // D) - (X // (D*C/x)))))

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 * i%D):
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
a, b, c, d = list(map(int, input().split()))
def f(a, b, x):
    if a % x == 0 or b % x == 0:
        return (b-a)//x + 1
    else:
        if (b-a) % x == 0:
            return (b-a)//x
        else:
            return (b-a)//x + 1

x = f(a,b,c)
y = f(a,b,d)
z = f(a,b,c*d)
print(b-a+1-x-y+z)

Submission status: Wrong Answer

Solution code:
import math
input = list(map(int,input().split()))
A = input[0]
B = input[1]
C = input[2]
D = input[3]

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

betweenAandB = B-A+1

cA = math.ceil(A/C)
cB = int(B/C)
cDiv = cB - cA + 1

dA = math.ceil(A/D)
dB = int(B/D)
dDiv = dB - dA + 1

GCD = gcd(C,D)
LCM = C*D/GCD

lcmA = math.ceil(A/LCM)
lcmB = int(B/LCM)
lcmDiv = lcmB - lcmA + 1

ans = betweenAandB - cDiv - dDiv + lcmDiv
print(ans)

Submission status: Wrong Answer

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

A, B, C, D = map(int, input().split())
L = C * D // gcd(C, D)
c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
l = B // L - (A - 1) // L

print(A - B + 1 - c - d + l)

Submission status: Wrong Answer

Solution code:
import math
input = list(map(int,input().split()))
A = input[0]
B = input[1]
C = input[2]
D = input[3]

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

betweenAandB = B-A+1

cA = A/C
if cA < 1: cA = math.ceil(1/cA)
else: cA = math.ceil(A/C)
cB = int(B/C)
cDiv = cB - cA + 1

dA = A/D
if dA < 1: dA = math.ceil(1/dA)
else: dA = math.ceil(A/D)
dB = int(B/D)
dDiv = dB - dA + 1

GCD = gcd(C,D)
LCM = C*D/GCD

lcmA = math.ceil(A/LCM)
lcmB = int(B/LCM)
lcmDiv = max(lcmA, lcmB) - min(lcmA, lcmB) + 1

ans = betweenAandB - cDiv - dDiv + lcmDiv
print(ans)

Submission status: Wrong Answer

Solution code:
import math
input = list(map(int,input().split()))
A = input[0]
B = input[1]
C = input[2]
D = input[3]

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

betweenAandB = B-A+1

cA = math.ceil(A/C)
cB = int(B/C)
cDiv = cB - cA + 1

dA = math.ceil(A/D)
dB = int(B/D)
dDiv = dB - dA + 1

GCD = gcd(C,D)
LCM = C*D/GCD

lcmA = math.ceil(A/LCM)
lcmB = int(B/LCM)
lcmDiv = max(lcmA, lcmB) - min(lcmA, lcmB) + 1

ans = betweenAandB - cDiv - dDiv + lcmDiv
print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
A, B, C, D = map(int, input().split())
X = B//C - A//C
Y = B//D - A//D
E = (C*D)//gcd(C,D)
Z = B//E - A//E
print(B-A-X-Y+Z+1)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
A, B, C, D = map(int, input().split())
X = Y = Z = []
for x in range(A,B):
  if x%C==0:
    X.append(x)
for y in range(A,B):
  if y%D==0:
    Y.append(y)
E = (C*D)//gcd(C,D)
for z in range(A,B):
  if z%E==0:
    Z.append(z)
print(B-A-len(X)-len(Y)+len(Z)+2)

Submission status: Wrong Answer

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

A, B, C, D = map(int, input().split())
X = A - B + 1
Y = X//C
Z = X//D
E = C*D
F = gcd(C,D)
G = E//F
V = X//G
W = X-Y-Z+V
print(1-W)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
X = Y = Z = []
for x in range(A,B):
  if x%C==0:
    X.append(x)
for y in range(A,B):
  if y%D==0:
    Y.append(y)
for z in range(A,B):
  if z%C==0 and z%D==0:
    Z.append(z)
W = len(X)+len(Y)-len(Z)
print(B-A-W+2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

 
def lcm(x,y):
  return x*y/gcd(x,y)
 
def numantidiv(a,b,c):
    r=a-int(a/b)-int(a/c)+int(a/lcm(b,c))
    return r
 
a,b,c,d=(int(x) for x in input().split())
ans=numantidiv(b,c,d)-numantidiv(a-1,c,d)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import floor
 
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

 
def lcm(x,y):
  return x*y/gcd(x,y)
 
def numantidiv(a,b,c):
    r=a-a/b-a/c+a/lcm(b,c)
    return r
 
a,b,c,d=(int(x) for x in input().split())
ans=numantidiv(b,c,d)-numantidiv(a-1,c,d)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import floor
 
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

 
def lcm(x,y):
  return x*y/gcd(x,y)
 
def numantidiv(a,b,c):
    r=a-floor(a/b)-floor(a/c)+floor(a/lcm(b,c))
    return r
 
a,b,c,d=(int(x) for x in input().split())
ans=numantidiv(b,c,d)-numantidiv(a-1,c,d)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import floor
 
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

 
def lcm(x,y):
  return x*y/gcd(x,y)
 
def numantidiv(a,b,c):
    r=a-floor(a/b)-floor(a/c)+floor(a/lcm(b,c))
    return r
 
a,b,c,d=(int(x) for x in input().split())
ans=numantidiv(b,c,d)-numantidiv(a,c,d)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

numA, numB, numC, numD = map(int, input().split())

AsplitC = int((numA - 1) / numC)
BsplitC = int(numB / numC)
AsplitD = int((numA - 1) / numD)
BsplitD = int(numB / numD)
AsplitCandD = int((numA - 1) / int(numC * numD / fractions.gcd(numC, numD)))
BsplitCandD = int(numB / int(numC * numD / fractions.gcd(numC, numD)))

count = (numB - numA + 1) - ((BsplitC - AsplitC) + (BsplitD - AsplitD) - (BsplitCandD - AsplitCandD))

print(count)

Submission status: Wrong Answer

Solution code:
listf=input().split()
list1 = [ int(listf[x]) for x in range(len(listf))]

def caluc(x,a,b):
    return int(x/a) + int(x/b) - int(x/(a*b))

sum = list1[1] - list1[0] + 1
div = caluc(list1[1] , list1[2] , list1[3]) - caluc(list1[0] - 1 , list1[2] , list1[3])
print(sum - div)

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
from sys import stdin

def main():
    """
     解答をこちらに
    """
    a, b, c, d = list(map(int, input().split()))
    l = range(a,b)
    ans = 0

    for i in l:
        if i%c!=0 and i%d!=0:
            ans += 1
    print(ans)
    pass


if __name__ == "__main__":
    main()

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/gcd(a,b)*b

def g(X):
  return X - X//C - X//D + X//lcm(C,D)

ans = g(B) - g(A-1)
print(int(ans))