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: Runtime Error

Solution code:
import math

def smallestCommon(x,y):
    return (x * y) // math.gcd(x,y)


def caluclate(a, b, c, d):

    s1 = 2 if a / c < 2 else int(a / c)
    s2 = 2 if b / c < 2 else int(b / c)
    s3 = 2 if a / d < 2 else int(a / d)
    s4 = 2 if b / d < 2 else int(b / d)



    m1 = s2 - s1 + 1
    m2 = s4 - s3 + 1
    m3 = 0
    common = smallestCommon(c,d)
    commonB = common / c

    m3 = (s2 //commonB) - (s1 // commonB)

    return int(b - a + 1 - (m1 + m2 - m3))


S = input().split(" ")
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

result = caluclate(A,B,C,D)

print(result)

Submission status: Runtime Error

Solution code:
import math

def smallestCommon(x,y):
    return (x * y) // math.gcd(x,y)


def caluclate(a, b, c, d):

    s1 = 2 if a / c < 2 else int(a / c)
    s2 = 2 if b / c < 2 else int(b / c)
    s3 = 2 if a / d < 2 else int(a / d)
    s4 = 2 if b / d < 2 else int(b / d)



    m1 = s2 - s1 + 1
    m2 = s4 - s3 + 1
    m3 = 0
    common = smallestCommon(c,d)
    commonB = common / c

    m3 = (s2 //commonB) - (s1 // commonB)

    return int(b - a + 1 - (m1 + m2 - m3))


S = input().split(" ")
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

result = caluclate(A,B,C,D)

print(result)

Submission status: Runtime Error

Solution code:
import numpy as np
a,b,c,d=map(int,input().split())
ab=np.array(range(a,b+1))
print(np.count_nonzero((ab%c)*(ab%d)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from franctions import gcd
a, b, c, d = map(int, input().split())
if a == b:
    if a % c != 0 and a % d != 0:
        print(1)
    else:
        print(0)
    exit()
cd_lcm = c * d // gcd(c, d)
print(b - a + 1 - (b // c - a // c) - (b // d - a // d) + (b // cd_lcm - a // cd_lcm))

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = map(int, input().split())
if a == b:
    if a % c != 0 and a % d != 0:
        print(1)
    else:
        print(0)
    exit()
cd_lcm = c * d // math.gcd(c, d)
print(b - a + 1 - (b // c - a // c) - (b // d - a // d) + (b // cd_lcm - a // cd_lcm))

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = map(int, input().split())
cd_lcm = c * d // math.gcd(c, d)
l = b - a
print(l - (l // c + l // d - l // cd_lcm))

Submission status: Runtime Error

Solution code:
import math

# 最小公倍数
def lcm(x, y):
    return (x * y) // math.gcd(x, y)


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

c_a = a//c
c_b = b//c

d_a = a//d
d_b = b//d

lcm = lcm(min(c, d), max(c,d))

l_a = a//lcm
l_b = b//lcm




ans =  (b - a)  -  (c_b - c_a) - (d_b - d_a) + (l_b - l_a)

print(ans)

Submission status: Runtime Error

Solution code:
import math
import fractions

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

    quotient = []
    temp_lcm = fractions.gcd(c, d) // c * d
    for i, x in enumerate([c, d, temp_lcm]):
        temp = (b // x) - ((a-1) // x)
        quotient.append(temp)
    temp1 = b - a + 1
    ans = temp1 - (quotient[0] + quotient[1]) + quotient[2]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
import fractions
cd_gcd=c*d/gcd(c,d)
l=b-a+1
print(l-(l//c+l//d-l//(cd_gcd)))#c*d←ここをc.dの最小公倍数にする

Submission status: Runtime Error

Solution code:
import math

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

# 最小公倍数
cd = c * d // math.gcd(c, d)

cdiv = int(b / c) - int((a - 1) / c)
ddiv = int(b / d) - int((a - 1) / d)
cddiv = int(b / (cd)) - int((a - 1) / (cd))
ans = (b - a + 1) - (cdiv + ddiv-cddiv)

print(ans)

Submission status: Runtime Error

Solution code:
# 21:15
import math as math

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

def F(n,c,d):
    x = n
    x -= n//c
    x -= n//d
    lcm = c*d//math.gcd(c,d)
    x += n//lcm
    return x

print(F(b,c,d) - F(a-1,c,d))

Submission status: Runtime Error

Solution code:
# 21:15
import math

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

def F(n,c,d):
    x = n
    x -= n//c
    x -= n//d
    lcm = c*d//math.gcd(c,d)
    x += n//lcm
    return x

print(F(b,c,d) - F(a-1,c,d))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def func(x,y,z):
    if (x-y)%z==0:
        return (x-y)//z
    else:
        return (x-y)//z+1
def gid(x,y):
    ans=x%y
    x=y
    y=ans
    while True:
        ans=x%y
        if ans==0:
            return y
            break
        x=y
        y=ans
cd=[c,d]
cd.sort()
cd2=cd[1]*cd[0]//(gid(cd[1],cd[0]))
_c=func(b,a,c)
_d=func(b,a,d)
_cd2=func(b,a,cd2)
print((b-a+1)-(_c+_d-_cd2))

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
cd=[c,d]
cd.sort()
l=b-a+1

def func(n,m):
    if m%n!=0:
        return m//n+1
    else:
        return m//n

def func2(x,y):
    ans=x%y
    x=y
    y=ans
    while True:
        ans=x%y
        if ans==0:
            return y
        x=y
        y=ans
cd2=cd[1]*cd[0]//(func2(cd[1],cd[0]))
print(l-(func(c,l)+func(d,l)-func(cd2,l)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
	import math
	a,b,c,d = map(int,input().split())
	ans = 0
	
	e = int((c*d) / math.gcd(c,d))

	i = int(b/c)
	t = int(b/d)
	l = int(b/e)

	while a <= i * c <= b:
		ans += 1
		i -= 1

	while a <= t * d <= b:
		ans += 1
		t -= 1
	
	while a <= l * e <= b:
		ans -= 1
		l -= 1

	print(int(len(range(a,b+1)))-ans)

if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
def main():
	import math
	a,b,c,d = map(int,input().split())
	ans = 0
	
	e = (c*d) / math.gcd(c,d)

	i = int(b/c)
	t = int(b/d)
	l = int(b/e)

	while a <= i * c <= b:
		ans += 1
		i -= 1

	while a <= t * d <= b:
		ans += 1
		t -= 1
	
	while a <= l * e <= b:
		ans -= 1
		l -= 1

	print(int(len(range(a,b+1)))-ans)

if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
def main():
	import math
	a,b,c,d = map(int,input().split())
	ans = 0
	
	e = (c*d) /math.gcd(c,d)
	# print(e)

	i = int(b/c)
	t = int(b/d)
	l = int(b/e)
	# print(i,t)
	# ans_set = set()

	while a <= i * c <= b:
		# print("i*c= {}".format(i*c))
		# ans_set.add(i*c)
		ans += 1
		i -= 1

	while a <= t * d <= b:
		# print("i*d= {}".format(t*d))
		# ans_set.add(t*d)
		ans += 1
		t -= 1
	# print(ans_set)
	
	while a <= l * e <= b:
		# print("l*c*d= {}".format(l*c*d))
		# ans_set.add(l*c*d)
		ans -= 1
		l -= 1

	print(int(len(range(a,b+1)))-ans)
	# print(int(len(range(a,b+1)))-len(ans_set))

if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
def main():
	import math
	a,b,c,d = map(int,input().split())
	ans = 0
	
	e = c*d//math.gcd(c,d)
	# print(e)

	i = int(b/c)
	t = int(b/d)
	l = int(b/e)
	# print(i,t)
	# ans_set = set()

	while a <= i * c <= b:
		# print("i*c= {}".format(i*c))
		# ans_set.add(i*c)
		ans += 1
		i -= 1

	while a <= t * d <= b:
		# print("i*d= {}".format(t*d))
		# ans_set.add(t*d)
		ans += 1
		t -= 1
	# print(ans_set)
	
	while a <= l * e <= b:
		# print("l*c*d= {}".format(l*c*d))
		# ans_set.add(l*c*d)
		ans -= 1
		l -= 1

	print(int(len(range(a,b+1)))-ans)
	# print(int(len(range(a,b+1)))-len(ans_set))

if __name__ == "__main__":
	main()

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = list(map(int, input().split()))
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
lcm = lcm(C,D)
nbc = B//C
nbd = B//D
nbl = B//lcm 
nac = (A-1)//C
nad = (A-1)//D
nal = (A-1)//lcm 
ans = B - A + 1-((nbc+nbd-nbl)-(nac+nad-nal))
print(int(ans))

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = list(map(int, input().split()))
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
lcm = lcm(C,D)
nbc = B//C
nbd = B//D
nbl = B//lcm 

nac = (A-1)//C
nad = (A-1)//D
nal = (A-1)//lcm 
ans = B - A + 1-((nbc+nbd-nbl)-(nac+nad-nal))
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

A, B, C, D = MAP()
# Cで割り切れる数 = B/C - A/C
c_b = B//C
c_a = A//C if A%C else A//C-1
c = c_b-c_a

d_b = B//D
d_a = A//D if A%D else A//D-1
d = d_b-d_a

E = (C*D) // (math.gcd(C,D))
#print(E)
e_b = B//E
e_a = A//E if A%E else A//E-1
e = e_b - e_a

#print(c, d, e)

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

Submission status: Runtime Error

Solution code:
import sys
from math import gcd
a, b, c, d = [int(i) for i in sys.stdin.readline().split()]
gcd_cd = gcd(c, d)
lcm = c * d // gcd_cd
n_c = b // c - (a - 1) // c
n_d = b // d - (a - 1) // d
n_cd = b // lcm - (a - 1) // lcm
res = (b - a + 1) - n_c - n_d + n_cd
print(res)

Submission status: Runtime Error

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


def start(num: int) -> int:
    if A % num == 0:
        num_start = A + (A % num)
    else:
        num_start = A + (num - A % num)
    return num_start


def count_in_range(num_start: int, num: int) -> int:
    r = B - num_start
    return r // num + 1


def calc(num: int) -> int:
    return count_in_range(start(num), num)


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


c = calc
print((B - A + 1) - (calc(C) + calc(D) - calc(lcm(C, D))))

Submission status: Runtime Error

Solution code:
import fraction
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/fraction.gcd(c,d))+(a-1)//(c*d/fraction.gcd(c,d))))

Submission status: Runtime Error

Solution code:
import math

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

def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

ans = 0
lcm = lcm_base(C,D)
c_num = B//C - (A-1)//C 
d_num = B//D - (A-1)//D
diff = B//lcm - (A-1)//lcm

print(B-A+1-(c_num+d_num-diff))

Submission status: Runtime Error

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

import math

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

E = lcm(C, D)

n_a = (A - 1) // C + (A - 1) // D - (A - 1) // E
n_b = B // C + B // D - B // E

print((B - A + 1) - (n_b - n_a))

Submission status: Runtime Error

Solution code:
import math

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

def func(n, x, y):
    lcm = x * y // math.gcd(x, y)
    return n - (n // x + n // y - n // lcm)

print(func(b, c, d) - func(a - 1, c, d))

Submission status: Runtime Error

Solution code:
import numpy as np

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

e = c * d // np.gcd(c,d)
c_count = b // c - a // c
if a % c == 0:
    c_count += 1
d_count = b // d - a // d
if a % d == 0:
    d_count += 1
e_count = b // e - a // e
if a % e == 0:
    e_count += 1

ans = b - a + 1 - (c_count + d_count - e_count)

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

e = c * d // math.gcd(c,d)
c_count = b // c - a // c
if a % c == 0:
    c_count += 1
d_count = b // d - a // d
if a % d == 0:
    d_count += 1
e_count = b // e - a // e
if a % e == 0:
    e_count += 1

ans = b - a + 1 - (c_count + d_count - e_count)

print(ans)

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
if d>c:
  euclid2,euclid1=c,d
  e1,e2=euclid1,euclid2
  while not euclid2==0:
    euclid1=euclid1%euclid2
    euclid1,euclid2=euclid2,euclid1
    cd=c*d//euclid1
if c>d:
  euclid2,euclid1=d,c
  e1,e2=euclid1,euclid2
  while not euclid2==0:
    euclid1=euclid1%euclid2
    euclid1,euclid2=euclid2,euclid1
    cd=c*d//euclid1
  
c1=(a-1)//c
c2=(b-c1*c)//c+1
d1=(a-1)//d+1
d2=(b-d1*d)//d+1
cd1=(a-1)//cd+1
cd2=(b-cd1*cd)//(c*d)+1  
print(b-a+1-c2-d2+max(0,cd2))

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
import math
cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
gcd=math.gcd(c,d)
lcm=c*d//gcd
cd=b//lcm-(a-1)//lcm
print((b-a+1)-(cc+dd-cd))

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
import math
cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
gcd=math.gcd(c,d)
lcm=c*d//gcd
cd=b//lcm-a//lcm
print((b-a+1)-(cc+dd-cd))

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
import math
cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
gcd=math.gcd(c,d)
lcm=c*d//gcd
cd=b//lcm-a//lcm
print((b-a+1)-(cc+dd-cd))

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
if c>b and d>b:
  print(b-a+1)
  exit()
elif c>b:
  for i in range(b):
    if d*i>=a:
      d1=i*d
  print(b-a-(b-d1)//d)
  exit()
elif d>b:
  for i in range(b):
    if c*i>=a:
      c1=i*c
  print(b-a-(b-c1)//c)
  exit()
else :
  clst=[c*i for i in range(a//c+1,(b-c*i)//c+i+1)]    
  dlst=[d*i for i in range(a//c+1,(b-d*i)//d+i+1)]
  lst=set(clst+dlst)
  print(b-a+1-len(lst))

Submission status: Runtime Error

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

print(b-a+1-k)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
(a,b,c,d)=map(int,input().split())
g=int(c*d/math.gcd(c,d))
k=0
k+=int(b/c)+int(b/d)-int(b/g)-int((a-1)/c)-int((a-1)/d)+int((a-1)/g)

print(b-a+1-k)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import fractions as gcd

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

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

c = B // C - A // C + (not A % C)
d = B // D - A // D + (not A % D)

x = lcm(C, D)
x = B // x - A // x + (not A % x)

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

Submission status: Runtime Error

Solution code:
from math import gcd

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

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

c = B // C - A // C + (not A % C)
d = B // D - A // D + (not A % D)

x = lcm(C, D)
x = B // x - A // x + (not A % x)

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

Submission status: Runtime Error

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

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

c_num = (B//C - (A-1)//C)
d_num = (B//D - (A-1)//D)
cd_num = (B//lcm(C, D) - (A-1)//lcm(C, D))
print((B-A+1) - (c_num+d_num-cd_num))

Submission status: Runtime Error

Solution code:
import math 

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

A,B,C,D = [int(i) for i in input().split(" ")]
AB = B-A
BC = AB//C
BD = AB//D
CD = lcm(C,D)
BCD = AB//CD
union = BC+BD-BCD
print(AB - union)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
def print_ans(A, B, C, D):
    """Test Case
    >>> print_ans(4, 9, 2, 3)
    2
    >>> print_ans(10, 40, 6, 8)
    23
    >>> print_ans(314159265358979323, 846264338327950288, 419716939, 937510582)
    532105071133627368
    """
    ar = np.arange(A, B + 1)
    cr = ar[ar % C != 0]
    dr = cr[cr % D != 0]
    print(len(dr))

if __name__ == '__main__':
    A, B, C, D = map(int, input().rstrip().split())
    print_ans(A, B, C, D)

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = map(int,input().split())
countC = math.floor(B/C) - math.floor((A-1)/C)
countD = math.floor(B/D) - math.floor((A-1)/D)
def lcm(x,y):
    return(x*y)//math.gcd(x,y)
lcmCD = lcm(C,D)
countlcm = math.floor(B/lcmCD) - math.floor((A-1)/lcm(C,D))
print(B - A + 1 - (countC + countD - countlcm))

Submission status: Runtime Error

Solution code:
import math

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

# 最小公倍数を求める
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

def cal(num, a, b):
    x = num // a
    y = num // b
    z = num // (lcm(a, b))
    print('z={}'.format(z))
    return num - (x + y - z)

num_a = cal(b, c, d)
num_b = cal(a-1, c, d)

print(num_a - num_b)

Submission status: Runtime Error

Solution code:
import math
import sys

num = list(map(int, input().split()))

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

def ans_mthd(i, j, k):
    return i - i // j - i // k + i * math.gcd(j, k) / j // k 

ans = ans_mthd(B, C, D)-ans_mthd(A-1, C, D)
# print(math.gcd(C, D))
# print(C * D)
# print(ans_mthd(B, C, D) // 1)
print(ans)

Submission status: Runtime Error

Solution code:
from decimal import *
import math
import sys

num = list(map(int, input().split()))

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

def ans_mthd(i, j, k):
    return Decimal((i - i // j - i // k + i * math.gcd(j, k) / j // k ))

ans = ans_mthd(B, C, D)-ans_mthd(A-1, C, D)
# print(math.gcd(C, D))
# print(C * D)
# print(ans_mthd(B, C, D) // 1)
print(ans)

Submission status: Runtime Error

Solution code:
import math

a, b, c, d = list(map(int, input().split()))
lcm = math.floor((c * d) / math.gcd(c, d))

b_c_cnt = math.floor(b / c)
b_d_cnt = math.floor(b / d)
b_lcm_cnt = math.floor(b / lcm)

b_cnt = b - (b_c_cnt + b_d_cnt) + b_lcm_cnt

a_c_cnt = math.floor(a / c)
a_d_cnt = math.floor(a / d)
a_lcm_cnt = math.floor(a / lcm)

a_cnt = a - (a_c_cnt + a_d_cnt) + a_lcm_cnt

if (a % c != 0 and a % d != 0):
    print(b_cnt - a_cnt + 1)
else:
    print(b_cnt - a_cnt)

Submission status: Runtime Error

Solution code:
import math

a, b, c, d = list(map(int, input().split()))
lcm = (c * d) // math.gcd(c, d)

b_c_cnt = b // c
b_d_cnt = b // d
b_lcm_cnt = b // lcm

b_cnt = b - (b_c_cnt + b_d_cnt) + b_lcm_cnt

a_c_cnt = a // c
a_d_cnt = a // d
a_lcm_cnt = a // lcm

a_cnt = a - (a_c_cnt + a_d_cnt) + a_lcm_cnt

if (a % c != 0 and a % d != 0):
    print(b_cnt - a_cnt + 1)
else:
    print(b_cnt - a_cnt)

Submission status: Runtime Error

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

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

    A_num = (A-1)//C + (A-1)//D - (A-1)//lcm(C, D)
    B_num = B//C + B//D - B//lcm(C, D)
    return (B-(A-1))-(B_num - A_num)


if __name__ == '__main__':
    print(main())

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = map(int, input().split())
l = int((B-A)/C)
m = int((B-A)/D)
lcm = C*D/math.gcd(C,D)
c = B-A-l-m+int((B-A)/lcm)
print(c)

Submission status: Runtime Error

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

l = int((B-A)/C)
m = int((B-A)/D)
lcm = C*D/math.gcd(C,D)
c = B-A-l-m+int((B-A)/lcm)
print(c)

Submission status: Runtime Error

Solution code:
import math

a, b, c, d = map(int, input().split())
cxd = (c * d) // math.gcd(c, d)
sa = b - a

ans = (b - b//c - b//d + b//cxd) - ((a-1) - (a-1)//c - (a-1)//d + (a-1)//cxd)

print(ans)

Submission status: Runtime Error

Solution code:
import math

a, b, c, d = map(int, input().split())
cxd = (c * d) // math.gcd(c, d)
sa = b - a

print(sa - ((sa//c + sa//d) - sa//cxd))

Submission status: Runtime Error

Solution code:
import math
# 最小公倍数
def lcm(x, y):
    return (x * y) // math.gcd(x, y)    
a, b, c, d = map(int, input().split())
e = lcm(c, d)
#print("e: {}".format(e))
#print("c: {} - {}".format(b // c, (a - 1) // c))
#print("d: {} - {}".format(b // d, (a - 1) // d))
#print("e: {} - {}".format(b // e, (a - 1) // e))
count_c = b // c - (a - 1) // c
count_d = b // d - (a - 1) // d
count_e = b // e - (a - 1) // e
# b - a の中から d の倍数の個数を取得
#print("count_c: {}".format(count_c))
#print("count_d: {}".format(count_d))
#print("count_e: {}".format(count_e))
print(b - a + 1 - (count_c + count_d - count_e))

Submission status: Runtime Error

Solution code:
import math

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

c_num = (b // c - math.ceil(a / c) + 1)
d_num = (b // d - math.ceil(a / d) + 1)


def lcm(x, y):
    return (x * y) // math.gcd(x, y)
    
e = lcm(c,d)

e_num = (b // e - math.ceil(a / e) + 1)

print((b-a+1)-(c_num+d_num-e_num))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math

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

ans = 0

CD = (C * D) // math.gcd(C, D) 

def l(a, x):
    if a // x == 0:
        return 1
    if a % x != 0:
        t = a // x + 1
        return t
    t = a // x
    return t

cl = l(A, C)
dl = l(A, D)
cdl = l(A, CD)
cr = B // C
dr = B // D
cdr = B // (CD)

ans = B - A + 1 - (cr - cl + 1) - (dr - dl + 1) + (cdr - cdl + 1)
        
print(ans)

Submission status: Runtime Error

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

def num_of_complements(x,c,d):
    lcm = c * d // math.gcd(c, d)
    num = x + x//lcm - x//c - x//d
    return num

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

Submission status: Runtime Error

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

def num_of_complements(x,c,d):
    num = x + x//lcm - x//c - x//d
    return num

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

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
import math
lcm = c * d // math.gcd(c, d)
def num_of_complements(x,c,d):

    num = x + x//lcm - x//c - x//d
    return num

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

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
import math
lcm = c * d // math.gcd(c, d)
def num_of_complements(x,c,d):

    num = x + x//lcm - x//c - x//d
    return num

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

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
import math
def num_of_complements(x,c,d):
    lcm = c * d // math.gcd(c, d)
    num = x + x//lcm - x//c - x//d
    return num

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

Submission status: Runtime Error

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

first_c = ( A - 1) // C
first_d = ( A - 1) // D
first_cd = ( A - 1) // lcm 
first = ( A - 1 ) - ( first_c + first_d - first_cd )

end_c = B // C
end_d = B // D
end_cd = B // lcm 
end_ = B - ( end_c + end_d - end_cd )

print(end_ - first)

Submission status: Runtime Error

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

first_c = ( A - 1) // C
first_d = ( A - 1) // D
first_cd = ( A - 1) // lcm 
first = ( A - 1 ) - ( first_c + first_d - first_cd )

end_c = B // C
end_d = B // D
end_cd = B // lcm 
end_ = B - ( end_c + end_d - end_cd )

print(end_ - first)

Submission status: Runtime Error

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

first_c = int( ( A - 1) / C)
first_d = int( ( A - 1) / D)
first_cd = int( ( A - 1) / lcm )
first = ( A - 1 ) - ( first_c + first_d - first_cd )

end_c = int( B / C)
end_d = int( B / D)
end_cd = int( B / lcm )
end_ = B - ( end_c + end_d - end_cd )

print(end_ - first)

Submission status: Runtime Error

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

first_c = int( ( A - 1) / C)
first_d = int( ( A - 1) / D)
first_cd = int( ( A - 1) / lcm )
first = ( A - 1 ) - ( first_c + first_d - first_cd )

end_c = int( B / C)
end_d = int( B / D)
end_cd = int( B / lcm )
end_ = B - ( end_c + end_d - end_cd )

print(end_ - first)

Submission status: Runtime Error

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

first_c = int( ( A - 1) / C)
first_d = int( ( A - 1) / D)
first_cd = int( ( A - 1) / lcm )
first = ( A - 1 ) - ( first_c + first_d - first_cd )

end_c = int( B / C)
end_d = int( B / D)
end_cd = int( B / lcm )
end_ = B - ( end_c + end_d - end_cd )

print(end_ - first)

Submission status: Runtime Error

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

first_c = int( ( A - 1) / C)
first_d = int( ( A - 1) / D)
first_cd = int( ( A - 1) / lcm )
first = ( A - 1 ) - ( first_c + first_d - first_cd )

end_c = int( B / C)
end_d = int( B / D)
end_cd = int( B / lcm )
end = B - ( end_c + end_d - end_cd )

print(end - first)

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = map(int,input().split())
lcm = int( C * D / math.gcd(C,D) )
c_round = 0
ans = 0
for i in range(1, lcm + 1):
    if i % C != 0 and i % D != 0:
        c_round += 1

b = int( A / lcm )
start = A %lcm

for i in range(start, lcm + 1):
    if i % C != 0 and i % D != 0:
        ans += 1

c = int(  B  / lcm )
ans += ( c_round * (c-b-1) )
end = B % lcm

for i in range(1,end + 1):
    if i % C != 0 and i % D != 0:
        ans += 1
print(ans)

Submission status: Runtime Error

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

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

lcmv = lcm(C, D)
bc = B // C
bd = B // D
bl = B // lcmv
ac = (A-1) // C
ad = (A-1) // D
al = (A-1) // lcmv
print(B - A + 1 - ((bc + bd - bl) - (ac + ad - al)))

Submission status: Runtime Error

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

import math

def div(x):
    if(a%x == 0):
        return (b//x-a//x)*(x-1)+(b%x)
    else:
        return (b//x-a//x)*(x-1)+(b%x)-(a%x-1)

ans = div(c)+div(d)-div(int(c*d/math.gcd(c,d)))
print(ans)

Submission status: Runtime Error

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

import math

def div(x):
    #print("{}:{},{},{}".format(x,(b//x-a//x)*(x-1),(b-b//x*x),(a-a//x*x)))
    if(a%x == 0):
        return (b//x-a//x)*(x-1)+(b%x)
    else:
        return (b//x-a//x)*(x-1)+(b%x)-(a%x-1)


print(div(c)+div(d)-div(int(c*d/math.gcd(c,d))))

Submission status: Runtime Error

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_1 = B // C
num_B_2 = B // D
num_B_3 = 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_1 = (A - 1) // C
num_A_2 = (A - 1) // D
num_A_3 = ((A - 1) // l
num_A = (A - 1) - (num_A_1 + num_A_2 - num_A_3)

print(num_B - num_A)

Submission status: Runtime Error

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

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

lem = int((C * D) / math.gcd(C, D)) 
num_lem = multiple(A, B, lem)

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

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
def gcd(x,y):
  if x%y==0:
    return y
  else:
    return gcd(x%y,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: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
def gcd(x,y):
  if x%y==0:
    return y
  else:
    return gcd(x%y,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: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
def gcd(x,y):
  if x%y==0:
    print(y)
  else:
    gcd(x%y,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: Runtime Error

Solution code:
import math

a, b, c, d = map(int, input().split())
# print(b - a + 1)
e = c * d // math.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: Runtime Error

Solution code:
def gcd(x,y):
  if(y==0):
  	return x
  if(x<y):
    x,y=y,x
  return gcd(y,x % y)
def lllen(a,b,c):
  at=a//c
  at=at*c
  b=b//c *c
  ansc=0
  while(at<a):
    at+=c
  ansc=b-at
  if ansc<0 :
  	ansc=0
  else:
  	ansc=ansc//c + 1
  	return ansc

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

ansc=lllen(a,b,c)
ansd=lllen(a,b,d)
ansl=lllen(a,b,(c*d)//gcd(c,d))
#print(ansc,ansl,ansd)
print(b-a+1 -ansc -ansd + ansl)

Submission status: Runtime Error

Solution code:
def gcd(x,y):
  if(y==0):
  	return x
  if(x<y):
    x,y=y,x
  return gcd(y,x % y)
def lllen(a,b,c):
  at=a//c
  at=at*c
  b=b//c *c
  ansc=0
  while(at<a):
    at+=c
  ansc=b-at
  if ansc<0 :
  	ansc=0
  else:
  	ansc=ansc//c + 1
  	return ansc

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

ansc=lllen(a,b,c)
ansd=lllen(a,b,d)
ansl=lllen(a,b,(c*d)//gcd(c,d))
print(ansc,ansl,ansd)
print(b-a+1 -ansc -ansd + ansl)

Submission status: Runtime Error

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

divc = b // c - (a-1) // c
divd = b // d - (a-1) // d

lcmcd = c * d // math.gcd(c,d)
divcd = b // lcmcd - (a-1) // lcmcd

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

Submission status: Runtime Error

Solution code:
import math
def resolve():
    a, b, c, d = list(map(int, input().split()))
    lcm = int(c * d / math.gcd(c, d))
    c_b = b - (b//c + b//d - b//(lcm))
    c_a = (a-1) - ((a-1)//c + (a-1)//d - (a-1)//(lcm))
    print(c_b - c_a)
    
resolve()

Submission status: Runtime Error

Solution code:
import math
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 / math.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: Runtime Error

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

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

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