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:
# abc131_c.py
'''
M を C,D でそれぞれ割り切れるもの
N を CD の最小公倍数で割り切れるもの
とすると
(B - A + 1) - (M - N)
で求められるはず
'''
import math
import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

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

A,B,C,D = map(int,input().split())
M1 = math.floor(B/C) + math.floor(B/D)
M2 = math.floor((A-1)/C) + math.floor((A-1)/D)
N1 = math.floor(B/lcm(C,D))
N2 = math.floor((A-1)/lcm(C,D))
# print(M1,M2,N1,N2)

print(B-A+1-(M1-M2-N1+N2))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

a, b, c, d = list(map(int, input().split()))
#b = list(map(int, input().split()))
total = b-a+1
lcm = int((c*d)/gcd(c, d))

d1 = b//c - a//c
d2 = b//d - a//d
add = b//lcm - a//lcm
if a % c == 0:
    d1 += 1
if a % d == 0:
    d2 += 1

print(total-d1-d2+add)

Submission status: Wrong Answer

Solution code:

import math
import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

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

A,B,C,D = map(int,input().split())
r = (B - A + 1)
M = math.ceil(r/C) + math.ceil(r/D)
N = math.ceil(r/lcm(C,D))
print(r-M+N)

Submission status: Wrong Answer

Solution code:

def gcd(a,b):
	if a==0:
		return b
	else:
		return gcd(b%a,a)
def lcm(a,b):
	return (a*b)/gcd(a,b)

def main():
	a ,b,c,d = map(int,input().split())
	lc = lcm(c,d)
	cnt = (((b)//c)-((a-1)//c))+(((b)//d)-((a-1)//d))- (((b)//(lc))-((a-1)//(lc)))
	print((b-(a-1))-cnt)
	

main()

Submission status: Wrong Answer

Solution code:
import math
def gcd(a,b):
	if a==0:
		return b
	else:
		return gcd(b%a,a)
def lcm(a,b):
	return (a*b)/gcd(a,b)

def main():
	a ,b,c,d = map(int,input().split())
	lc = lcm(c,d)
	cnt = (math.floor((b)/c)-math.floor((a)/c))+(math.floor((b)/d)-math.floor((a)/d))- (math.floor((b)/(lc))-math.floor((a)/(lc)))
	print((b-(a-1))-cnt)
	

main()

Submission status: Wrong Answer

Solution code:
import math
def gcd(a,b):
	if a==0:
		return b
	else:
		return gcd(b%a,a)
def lcm(a,b):
	return (a*b)/gcd(a,b)

def main():
	a ,b,c,d = map(int,input().split())
	lc = lcm(c,d)
	cnt = (math.floor((b)/c)-math.floor((a)/c))+(math.floor((b)/d)-math.floor((a)/d))- (math.floor((b)/(lc))-math.floor((a)/(lc)))
	print((b-(a-1))-cnt)
	

main()


# 1 2 3 4 5
# 1 3 3 4 5
# 1 4 3 4 5

Submission status: Wrong Answer

Solution code:
import math
def gcd(a,b):
	if a==0:
		return b
	else:
		return gcd(b%a,a)
def lcm(a,b):
	return (a*b)/gcd(a,b)

def main():
	a ,b,c,d = map(int,input().split())
	lc = lcm(c,d)
	cnt = (math.floor((b)/c)-math.floor((a-1)/c))+(math.floor((b)/d)-math.floor((a-1)/d))- (math.floor((b)/(lc))-math.floor((a-1)/(lc)))
	print((b-(a-1))-cnt)
	

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
e=a
t=0
while e<=b:
  if e%c!=0 or e%d!=0:
    t+=1
  e+=1
print(t)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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())
print(b-a+1-(b//c+b//d-b//(c*d)-a//c-a//d+a//(c*d)))

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//c+a//d-a//(c*d)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int, input().split())
x = (c*d) // gcd(c,d)
c1, d1, cd1 = b // c, b // d, b // x
c2, d2, cd2 = (a-1) // c, (a-1) // d, a // x
ans = (c1+d1-cd1) - (c2+d2-cd2)
print(b-a+1-ans)

Submission status: Wrong Answer

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

c1, d1, cd1 = b // c, b // d, b // (c*d)
c2, d2, cd2 = (a-1) // c, (a-1) // d, a // (c*d)
ans = (c1+d1-cd1) - (c2+d2-cd2)
print((b-a+1) - ans)

Submission status: Wrong Answer

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

c1, d1, cd1 = b // c, b // d, b // (c*d)
c2, d2, cd2 = (a-1) // c, (a-1) // d, a // (c*d)
ans = (c1+d1-cd1) - (c2+d2-cd2)
print(ans)
print((b-a+1) - ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import math
a,b,c,d = map(int,input().split())
dum = b-a
ans1 = dum//c
ans2 = dum//d
ans3 = dum//(c*d/gcd(c,d))

print(math.ceil(dum-ans1-ans2+ans3))
#print(ans1,ans2,ans3)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

A, B, C, D = map(int, input().split())
r = B - A
print(r - r // C - r // D + r // (C * D // gcd(C, D)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

def div_n(a,b,n):
    if a%n != 0:
        marker1 = a + (n - a%n)
    else:
        marker1 = a
        
    if b%n != 0:
        marker2 = b - (n - b%n)
    else:
        marker2 = b
    return (marker2 - marker1)//n + 1

all_cnt = (b-a)+1
a_cnt = div_n(a,b,c)
b_cnt = div_n(a,b,d)
c_cnt = div_n(a,b,lcm(c,d))

print(all_cnt - a_cnt - b_cnt + c_cnt)

Submission status: Wrong Answer

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

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

def div_n(a,b,n):
    marker1 = a + (n - a%n)
    marker2 = b - (n - b%n)
    return (marker2 - marker1)//n + 1

all_cnt = (b-a)+1
a_cnt = div_n(a,b,c)
b_cnt = div_n(a,b,d)
c_cnt = div_n(a,b,lcm(c,d))

print(all_cnt - a_cnt - b_cnt + c_cnt)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
count=0
def cc(a,b,c):
    if a%c==0 or b%c==0:
        return (b-a)//c+1
    else:
        return (b-a)//c
print(b-a+2-cc(a,b,c)-cc(a,b,d)+cc(a,b,(a*b)//fractions.gcd(c,d)))

Submission status: Wrong Answer

Solution code:
data = input().split()

a = int(data[0])
b = int(data[1])
c = int(data[2])
d = int(data[3])

multi = c * d

count = 0

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

print(count)

Submission status: Wrong Answer

Solution code:
import fractions
import math
a,b,c,d = map(int, input().split())
x1 = (a-1)//c
x2 = b//c
x = x2-x1
y1 = (a-1)//d
y2 = b//d
y = y2-y1
z1 = (a-1)//((c*d)/fractions.gcd(c,d))
z2 = b//((c*d)/fractions.gcd(c,d))
z = z2-z1
print(int((b-a+1)-x-y+z))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int, input().split())
x1 = (a-1)//c
x2 = b//c
x = x2-x1
y1 = (a-1)//d
y2 = b//d
y = y2-y1
z1 = (a-1)//((c*d)/fractions.gcd(c,d))
z2 = b//((c*d)/fractions.gcd(c,d))
z = z2-z1
print(x,y,z)
print((b-a+1)-x-y+z)

Submission status: Wrong Answer

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

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

from math import ceil, floor
from fractions import gcd

def solve():
    a, b, c, d = MI()

    e = floor(b / c)
    f = ceil(a / c)
    c2 = e - f + 1
    g = floor(b / d)
    h = ceil(a / d)
    d2 = g - h + 1

    cd = lcm(c, d)
    cdr = floor(b / cd)
    cdl = ceil(a / cd)
    cd2 = cdr - cdl + 1
    # print(c2, d2, cd2)
    print(b - a + 1 - c2 - d2 + cd2)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

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

from math import ceil
from fractions import gcd

def solve():
    a, b, c, d = MI()

    e = b // c
    f = ceil(a / c)
    c2 = e - f + 1
    g = b // d
    h = ceil(a / d)
    d2 = g - h + 1

    cd = lcm(c, d)
    cdr = b // cd
    cdl = ceil(a / cd)
    cd2 = cdr - cdl + 1
    # print(c2, d2, cd2)
    print(b - a + 1 - c2 - d2 + cd2)


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
def main():
    import fractions
    a,b,c,d=map(int, input().split())
    def lcm(c,d):
        return c*d//fractions.gcd(c,d)
    e=lcm(c,d)
    ans=(b-a+1)-((b//c-a//c)+(b//d-a//d))+(b//e-a//e)
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A, B, C, D = map(int, input().split())
A -= 1
L = (C*D)/gcd(C,D)
a = A - ((A//C)+(A//D)-(A//L))
b = B - ((B//C)+(B//D)-(B//L))
print(int(b - a))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A, B, C, D = map(int, input().split())
A -= 1
L = C*D/gcd(C,D)
a = A - ((A//C)+(A//D)-(A//L))
b = B - ((B//C)+(B//D)-(B//L))
print(int(b - a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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//C)+(A//D)-(A//(C*D)))))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int,input().split())
ans = 0
l = c * d // gcd(c, d)
for i in range(a,b+1):
  if i % l != 0:  
    ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import math

numC = 0
numD_C = 0

cA = math.ceil(A/C)
cB = math.ceil(B/C)
dA = math.ceil(A/D)
dB = math.ceil(B/D)

i = 1
num = 0

while A <= C*D*i <=B:
    num += 1
    i += 1

ans = B-A +1-(abs(cB-cA) + abs(dB-dA) - num)

print(ans)

Submission status: Wrong Answer

Solution code:
def countDivBy(d,a,b):
    resB=int(b/d)
    resA=int((a-1)/d)
    res = resB-resA
    return res

def gcd(c,d):
    if(d>c):
        c,d = d,c
    a,b=c,d
    r=a%b
    while (r>0):      
        a = b
        b = r 
        r = a%b
    return b
  
A = list(map(int, input().split()))
a, b, c, d = A
g = gcd(c,d)
lcm = int(c*d/g)
ans = b - a + 1 - countDivBy(c,a,b) - countDivBy(d,a,b) + countDivBy(lcm,a,b)
print(ans)

Submission status: Wrong Answer

Solution code:
def countDivBy(d,a,b):
    resB=int(b/d)
    resA=int(a/d)
    res = resB-resA
    if(a%d==0):
        res+=1
    return res
  
def gcd(c,d):
    if(d>c):
        c,d = d,c
    a,b=c,d
    r=a%b
    while (r>0):      
        a = b
        b = r 
        r = a%b
    return b
  
A = list(map(int, input().split()))
a, b, c, d = A
g = gcd(c,d)
lcm = int(c*d/g)
ansC = countDivBy(c,a,b)
ansD = countDivBy(d,a,b)
ansCD = countDivBy(lcm,a,b)
ans = b - a + 1 - ansC - ansD + ansCD
print(ans)

Submission status: Wrong Answer

Solution code:
def countDivBy(d,a,b):
    resB=int(b/d)
    resA=int(a/d)
    res = resB-resA
    if(a%d==0):
        res+=1
    return res
  
def gcd(c,d):
    if(d>c):
        c,d = d,c
    a,b=c,d
    r=a%b
    while (r>0):      
        a = b
        b = r 
        r = a%b
    return b

A = list(map(int, input().split()))
a, b, c, d = A
g = gcd(c,d)
lcm = int(c*d/g)
ans = b - a + 1 - countDivBy(c,a,b) - countDivBy(d,a,b) + countDivBy(lcm,a,b)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#C
import math
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

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

print((bb - aa))

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D=map(int,input().split())
#B以下のものの数からA以下のものの数を引く
e=fractions.gcd(C,D)
a_c=(A-1)//C #A以下のCの倍数
b_c=B//C  #B以下のCの倍数
a_d=(A-1)//D
b_d=B//D
if e==C*D:
  s=A-1-(a_c+a_d)
  t=B-(b_c+b_d)
  u=t-s
  print(u)
else:
  a_cd=(A-1)//e #A以下のうちｃでもｄでも割り切れるもの
  b_cd=B//e
  s=A-1-(a_c+a_d-a_cd)
  t=B-(b_c+b_d-b_cd)
  u=t-s
  print(u)

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D=map(int,input().split())
#B以下のものの数からA以下のものの数を引く
e=fractions.gcd(C,D)
a_c=A//C #A以下のCの倍数
b_c=B//C  #B以下のCの倍数
a_d=A//D
b_d=B//D
if e==C*D:
  s=A-(a_c+a_d)
  t=B-(b_c+b_d)
  u=t-s
  print(u)
else:
  a_cd=A//e #A以下のうちｃでもｄでも割り切れるもの
  b_cd=B//e
  s=A-(a_c+a_d-a_cd)
  t=B-(b_c+b_d-b_cd)
  u=t-s
  print(u)

Submission status: Wrong Answer

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

U = B - A + 1
U_c = B // C - A // C
U_d = B // D - A // D
U_cd = B // CD - A // CD

ans = U - (U_c + U_d - U_cd) - sum([A % C == 0, A % D == 0, A % CD == 0])
print(ans)

Submission status: Wrong Answer

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

U = B - A + 1
U_c = U // C
U_d = U // D
U_cd = U // (C * D // gcd(C, D))

ans = U - (U_c + U_d - U_cd)
if A % 4 == 0 or B % 4 == 0:
    ans -= 1
print(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 == i//c or i/d ==i//d:
        continue
    else:
        count +=1
print(count)

Submission status: Wrong Answer

Solution code:
import fractions
import math

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

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

c_left = math.ceil(A / C)
c_right = B // C

c = c_right - c_left + 1

d_left = math.ceil(A / D)
d_right = B // D

d = d_right - d_left + 1

left = math.ceil(A / lcm(C, D))
right = B // lcm(C, D)



print(B-A+1-(c+d-(right-left+1)))

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = list(map(int,input().split()))
A -= 1
lcn = C * D / fractions.gcd(C,D) 
m_n = B - B // C - B // D + B // lcn
min_n = A - A // C - A // D + A // lcn
print(int(m_n-min_n))

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = list(map(int,input().split()))
A -= 1
lcn = C * D / fractions.gcd(C,D) 
m_n = B - B // C - B // D + B // lcn
min_n = A - A // C - A // D + A // lcn
print(m_n-min_n)

Submission status: Wrong Answer

Solution code:
def main():
    import fractions 
    import math
    a,b,c,d = map(int,input().split())
    m = c*d//fractions.gcd(c,d)
    c_=math.ceil(a/c)*c
    d_=math.ceil(a/d)*d
    c__ = math.floor(b/c)*c
    d__ = math.floor(b/d)*d
    m_ = math.ceil(a/m)*m
    m__ = math.floor(b/m)*m
    print(b-a-((c__-c_)//c+(d__-d_)//d-(m__-m_)//m))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import fractions 
    import math
    a,b,c,d = map(int,input().split())
    m = int(c*d/fractions.gcd(c,d))
    c_=math.ceil(a/c)*c
    d_=math.ceil(a/d)*d
    c__ = math.floor(b/c)*c
    d__ = math.floor(b/d)*d
    m_ = math.ceil(a/m)*m
    m__ = math.floor(b/m)*m
    print(int(b-a-((c__-c_)//c+(d__-d_)//d-(m__-m_)//m)))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import floor
from fractions import gcd

lcm = lambda a, b: int(a * b / gcd(a, b))

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

calculate = lambda number, divider: number - floor(number / divider)
num = lambda number1, number2, divider: calculate(number2, divider) - calculate(number1 - 1, divider)
# print(
#     num(A, B, C),
#     num(A, B, D),
#     lcm(C, D),
#     B - A + 1 - num(A, B, C),
#     B - A + 1 - num(A, B, D),
#     floor(B / lcm(C, D)) - floor(A / lcm(C, D)),
# )
total = B - A + 1
num_of_dividable_c = total - num(A, B, C)
num_of_dividable_d = total - num(A, B, D)
foo = floor(B / lcm(C, D)) - floor((A - 1) / lcm(C, D))
answer = total - (num_of_dividable_c + num_of_dividable_d - foo)
print(answer)

Submission status: Wrong Answer

Solution code:
from math import floor
from fractions import gcd

lcm = lambda a, b: int(a * b / gcd(a, b))

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

calculate = lambda number, divider: number - floor(number / divider)
num = lambda number1, number2, divider: calculate(number2, divider) - calculate(number1 - 1, divider)
# print(
#     num(A, B, C),
#     num(A, B, D),
#     lcm(C, D),
#     B - A + 1 - num(A, B, C),
#     B - A + 1 - num(A, B, D),
#     floor(B / lcm(C, D)) - floor(A / lcm(C, D)),
# )
total = B - A + 1
answer = total - (total - num(A, B, C) + total - num(A, B, D) - floor(B / lcm(C, D)) + floor(A / lcm(C, D)))
print(answer)

Submission status: Wrong Answer

Solution code:
from math import floor
from fractions import gcd

lcm = lambda a, b: int(a * b / gcd(a, b))

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

calculate = lambda number, divider: number - floor(number / divider)
num = lambda number1, number2, divider: calculate(number2, divider) - calculate(number1 - 1, divider)
# print(
#     num(A, B, C),
#     num(A, B, D),
#     lcm(C, D),
#     B - A + 1 - num(A, B, C),
#     B - A + 1 - num(A, B, D),
#     floor(B / lcm(C, D)) - floor(A / lcm(C, D)),
# )

answer = B - A + 1 - (B - A + 1 - num(A, B, C) + B - A + 1 - num(A, B, D) - floor(B / lcm(C, D)) - floor(A / lcm(C, D)))
print(answer)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int,input().split())
if a % c == 0:
    c_times = b//c - a//c + 1
else:
    c_times = b//c - a//c
print(c_times)
if a % d == 0:
    d_times = b//d - a//d +1
else:
    d_times = b//d - a//d
print(d_times)
lcm = c*d // gcd(c,d)
if a % lcm == 0:
    lcm_times = b//lcm - a//lcm +1
else:
    lcm_times = b//lcm - a//lcm
print(lcm_times)
total = (b-a+1) - (c_times + d_times - lcm_times)
print(total)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    # 全体から、Ｃの倍数 + Ｄの倍数 - (CとDの倍数でもあるやつ)をひけええ
    # C と D の最小公倍数　これは　lcmだね ~ c * d // gcd(c,d)かな
    a,b,c,d = readInts()
    # A 以上　B 以下の中　＝ B以下 - (A-1以下)
    # まず最小公倍数を求めよう
    from fractions import gcd
    lcm = ( c // gcd(c,d) ) * d
    #print(lcm)
    # まず B 以下のやつ


    # 答えは C でも　D でも割り切れないやつだからｗｗｗｗｗｗｗ


    B_ = b - (b // c + b // d - b // lcm)
    #print(B_)
    # んで A-1以下のやつ
    A_ = a-1 - ((a-1) // c  + (a-1) // d + (a-1) // lcm)
    # んで答え
    print(B_ - A_)
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
import math
import fractions
a,b,c,d=map(int,input().split())
base=b-a+1
n_c=1+(b-c+1)//c-(a+c-1)//c+1
n_d=1+(b-d+1)//d-(a+d-1)//d+1
cd=c*d/fractions.gcd(c,d)
n_cd=1+(b-cd+1)//cd-(a+cd-1)//cd+1
print(base-n_c-n_d+n_cd)

Submission status: Wrong Answer

Solution code:
import math
import fractions
a,b,c,d=map(int,input().split())
base=b-a+1

n_c=math.floor(b/c)-math.ceil(a/c)+1
n_d=math.floor(b/d)-math.ceil(a/d)+1
cd=c*d/fractions.gcd(c,d)
n_cd=math.floor(b/cd)-math.ceil(a/cd)+1
print(base-n_c-n_d+n_cd)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

# cye bolunenler
c_numbers = int(b/c) - int((a-1)/c)
# dye bolunenler
d_numbers = b//d - (a-1)//d
# ortak bolunenler
gcd_number = c*d // gcd(c, d)
ortak = int(b/gcd_number) - int((a-1)/gcd_number)
# result
print(b-a+1-(c_numbers+d_numbers-ortak))

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d=map(int, input().split())
k=fractions.gcd(c, d)
lcm=c*d//k
x=b//c - a//c
y=b//d - a//d
z=b//lcm - a//lcm
print(b-a+1-(x+y-z))

Submission status: Wrong Answer

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

ans = b - a + 1
cd = c*d/fractions.gcd(c,d)
tmp = int(b / c) - int((a-1) / c)
tmp2 = int(b / d) - int((a-1) / d)
tmp3 = int(b / cd) - int((a-1) / cd)
print(ans - tmp - tmp2 + tmp3 )

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 or i % d == 0:
    pass
  else:
    count += 1
print(count)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A, B, C, D = map(int, input().split())
sc = B//C - (A-1)//C
sd = B//D - (A-1)//D
scd = B//gcd(C, D) - (A-1)//gcd(C, D)
# print(sc, sd, scd, B-A+1)
print(B-A+1 - sc - sd + scd)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A, B, C, D = map(int, input().split())
sc = B//C - (A-1)//C
sd = B//D - (A-1)//D
scd = B//gcd(C, D) - (A-1)//gcd(C, D)
print(sc, sd, scd, B-A+1)
print(B-A+1 - sc - sd + scd)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A,B,C,D = map(int,input().split())
all_count = B-A
c_count = all_count//C
d_count = all_count//D
cd_count = all_count//lcm(C,D)
ans = all_count - c_count - d_count + cd_count
print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
all_count = B-A
c_count = all_count//C
d_count = all_count//D
ans = all_count - c_count - d_count
print(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 fractions import gcd
a, b, c, d = list(map(int, input().split()))

c_cnt = b // c  - (a-1) // c
d_cnt = b // d  - (a-1) // d

lcm = c * d / gcd(c, d)
lcm_cnt = b // lcm  - (a-1) // lcm

print((b - a + 1) - (c_cnt + d_cnt - lcm_cnt))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
A,B,C,D = map(int,input().split())
import fractions
e = C * D
ans = 0
def X(n):
  a = n // C
  b = n // D
  c = n // e
  return n - a - b + c
print(X(B) - X (A-1))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
A,B,C,D = map(int,input().split())
import fractions
e = fractions.gcd(C,D)
f = C * D / e
b = B// f
a = (A-1) // f
print(int(b-a))

Submission status: Wrong Answer

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

num1 = c
num2 = d
while (num2>0):
  num1,num2 = max(num1,num2),min(num1,num2)
  r = num1%num2
  num1 = num2
  num2 = r
lcm = c*d/num1

n1 = (a-1)//c+(a-1)//d-(a-1)//lcm
n2 = b//c+b//d-b//lcm
n = n2-n1
ans = b-a+1-n
print(int(ans))

Submission status: Wrong Answer

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

n = b-a-1
n_c = n//c
n_d = n//d
n_gap = n//(c*d)

print(n-n_c-n_d+n_gap+1)

Submission status: Wrong Answer

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


def func(x,y):
    if(x<0):
        assert()
    if(y<=0):
        assert()
    # print(x,y,int(x/y))
    # return int((x/y))
    # print(x,y,x//y)
    return int((x//y))

# print(func(100,10))


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

Submission status: Wrong Answer

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


def func(x,y):
    if(x<0):
        assert()
    if(y<=0):
        assert()
    # print(x,y,int(x/y))
    # return int((x/y))
    # print(x,y,x//y)
    return (x//y)

# print(func(100,10))


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

Submission status: Wrong Answer

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


def func(x,y):
    if(x<0):
        assert()
    if(y<=0):
        assert()
    # print(x,y,int(x/y))
    # return int((x/y))
    # print(x,y,x//y)
    return (x//y)

# print(func(100,10))


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

Submission status: Wrong Answer

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


def func(x,y):
    if(x<0):
        assert()
    if(y<=0):
        assert()
    # print(x,y,math.floor((x/y)))
    return int((x/y))

# print(func(100,10))


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

Submission status: Wrong Answer

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


def func(x,y):
    if(x<0):
        assert()
    if(y<=0):
        assert()
    # print(x,y,math.floor((x/y)))
    return int((x/y))

# print(func(100,10))


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

Submission status: Wrong Answer

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


def func(x,y):
    if(x<0):
        assert()
    if(y<=0):
        assert()
    # print(x,y,math.floor((x/y)))
    return math.floor((x/y))

# print(func(100,10))


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

Submission status: Wrong Answer

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


def func(x,y):
    if(x<0):
        assert()
    if(y<=0):
        assert()
    # print(x,y,math.floor((x/y)))
    return math.floor((x/y))

# print(func(100,10))


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

Submission status: Wrong Answer

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


#     {x | A <= x <= B and x % C != 0 and x % D != 0}
# =             {x | 1 <= x <= B and x % C != 0 and x % D != 0}
#           -   {x | 1 <= x <= A-1 and x % C != 0 and x % D != 0}
# =   {x | 1 <= x <= B} - {x | 1 <= x <= B and x % C = 0} - {x | 1 <= x <= B and x % D = 0} + - {x | 1 <= x <= B and x % C = 0 and x % D = 0}
#     (略)

def func(x,y):
    # print(x,y,math.floor((x/y)))
    return math.floor((x/y))

# print(func(100,10))


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

Submission status: Wrong Answer

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


#     {x | A <= x <= B and x % C != 0 and x % D != 0}
# =             {x | 1 <= x <= B and x % C != 0 and x % D != 0}
#           -   {x | 1 <= x <= A-1 and x % C != 0 and x % D != 0}
# =   {x | 1 <= x <= B} - {x | 1 <= x <= B and x % C = 0} - {x | 1 <= x <= B and x % D = 0} + - {x | 1 <= x <= B and x % C = 0 and x % D = 0}
#     (略)

def func(x,y):
    # print(x,y,math.floor((x/y)))
    return math.floor((x/y))

# print(func(100,10))


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

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:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def gcd(a,b):
    divided=a
    div=b
    ex=1
    while ex>0:
        ex=divided%div
        divided=div
        div=ex
    return divided


a,b,c,d=MI()
g=c*d//gcd(c,d)
#print(g)
ansb=b-int(b/c)-int(b/d)+int(b/g)
ansa=a-1-int((a-1)/c)-int((a-1)/d)+int((a-1)/g)
ans=ansb-ansa
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def gcd(a,b):
    divided=a
    div=b
    ex=1
    while ex>0:
        ex=divided%div
        divided=div
        div=ex
    return divided


a,b,c,d=MI()
g=c*d//gcd(c,d)
#print(g)
ansb=b-int(b/c)-int(b/d)+int(b/g)
ansa=a-1-int((a-1)/c)-int((a-1)/d)+int((a-1)/g)
ans=ansb-ansa
print(ans)