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
a,b,c,d = list(map(int,input().split()))
cka = math.floor(b/c) - math.ceil(a/c) + 1
dka = math.floor(b/d) - math.ceil(a/d) + 1
lc= int((c*d)/math.gcd(c, d))
dcka = math.floor(b/lc) - math.ceil(a/lc) + 1
print(b-a+1-cka-dka+dcka)

Submission status: Runtime Error

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

x = int(b/c)
y = int(b/d)
lcm_xy = int(c*d/math.gcd(c,d))
xy = int(b/lcm_xy)
bb = x+y-xy

x = int(a/c)
y = int(a/d)
xy = int(a/lcm_xy)
aa = x+y-xy
print(al - (bb -aa))

Submission status: Runtime Error

Solution code:
import math
# input process
inputData = input().split()
A = int(inputData[0])
B = int(inputData[1])
C = int(inputData[2])
D = int(inputData[3])

C_q_num = (B // C) - (A // C)
if (B % C) == 0:
    C_q_num += 1
D_q_num = (B // D) - (A // D)
if (B % D) == 0:
    C_q_num += 1
CD_lcm = (C * D) // math.gcd(C, D)
CD_q_num = (B // CD_lcm) - (A // CD_lcm)
if (B % CD_lcm) == 0:
    CD_q_num += 1
print((B - A + 1) - C_q_num - D_q_num + CD_q_num)

Submission status: Runtime Error

Solution code:
#https://atcoder.jp/contests/abc131/tasks/abc131_c

import math

def gcd(a, b):
    if b == 0:
        return a
    else:
        while b:
            a, b = b, a % b
        return a
'''
def lcm(a,b):
	return a*b//gcd(a,b)
'''
a,b,c,d = [int(i) for i in input().split()]
'''
C = 0
D = 0
E = 0
'''
'''
for i in range(int(a / max(c,d,lcm(c,d))),b-a):
    print(i)
    if c * i >= a and c * i <= b and C == 0:
        C = c * i
    if d * i >= a and d * i <= b and D == 0:
        D = d * i
    if lcm(c,d) * i >= a and lcm(c,d) * i <= b and E == 0:
        E = lcm(c,d) * i
    if C != 0 and D != 0 and E != 0:
        break
'''
'''
for i in range(int(a / lcm(c,d)) - 1,int(b / lcm(c,d))+2):
    if lcm(c,d) * i >= a and lcm(c,d) * i <= b and E == 0:
        E = lcm(c,d) * i
        break

for i in range(int(a / c) - 1,int(b / c)+2):
    if c * i >= a and c * i <= b and C == 0:
        C = c * i
        break

for i in range(int(a / d) - 1,int(b / d)+2):
    if d * i >= a and d * i <= b and D == 0:
        D = d * i
        break
'''
#print(lcm(c,d))
#print('')
#print(C,D,E)
'''
c2 = int(b / c) - int(C / c)+1
d2 = int(b / d) - int(D / d)+1
e2 = int(b / lcm(c,d)) - int(E / lcm(c,d))+1
'''
'''
if int(b / c) == b/c:
	print('c')
	c2 += 1
if int(b / d) == b/d:
	print('d')
	d2 += 1
if int(b / lcm(c,d)) == b/lcm(c,d):
	print('e')
	e2 += 1
'''
c2 = int(b / c) - int((a-1) / c)
d2 = int(b / d) - int((a-1) / d)
e2 = int(b / (c*d/math.gcd(c,d))) - int((a-1)/(c*d/math.gcd(c,d)))
'''
if a % c == 0:
	#print('c')
	c2 += 1
if a % d == 0:
	#print('d')
	d2 += 1
if a % lcm(c,d) == 0:
	#print('e')
	e2 += 1
'''
'''
if E == 0:
	e2 = 0
if C == 0:
	c2 = 0
if D == 0:
	d2 = 0
'''

#print(b-a+1,c2,d2,e2)
'''
c1 = list(range(C,b+1,c))
d1 = list(range(D,b+1,d))
e1 = list(range(E,b+1,lcm(c,d)))
print(b-a+1,len(c1),len(d1),len(e1))

print(c1,d1,e1)

print(b-a+1-len(c1)-len(d1)+len(e1))
'''
print(int(b-a+1 - c2 - d2 + e2))

Submission status: Runtime Error

Solution code:
# 最初に入れておくとinputが早くなる
import sys
from math import gcd
input = sys.stdin.readline

a, b, c, d = map(int, input().split())
a -= 1
# warikireru = set()
# for i in range(b//c+1):
#    for j in range(b // d+1):
#        k = c ** i * d ** j
#        if(a <= k <= b):
#            warikireru.add(k)
# print(warikireru)
# print(b-a+1-len(warikireru))

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

print(b-a-b//c+a//c-b//d+b//k+a//d-a//k)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = np.empty((0,2),int)
for i in range(n):
    b = np.array([[int(i) for i in input().split()]])
    a = np.append(a,b,axis=0)
a = a[np.argsort(a[:, 1])]
ans = "Yes"
k = 0
for i in range(len(a)):
    k += a[i,0]
    if k > a[i,1]:
        ans = "No"
        break
print(ans)

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)
ret = 0
ret += B//C - (A-1)//C
ret += B//D - (A-1)//D
L = lcm(C, D)
ret -= B//L - (A-1)//L
print(B-A+1-ret)

Submission status: Runtime Error

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

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

# arr = np.linspace(A,B,1)
a1 = A-1 // C
a2 = A-1 // D

b1 = B // C
b2 = B // D 

ab1 = b1 - a1
ab2 = b2 - a2


lc = lcm(C,D)

a3 = A // lc
b3 = B // lc
ab3 = b3 - a3
res = ab1 + ab2 - ab3
print(abs(A-B)-res)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
import math
a,b,c,d = list(map(int,raw_input().split()))
cka = math.floor(b/c) - math.ceil(a/c) + 1
dka = math.floor(b/d) - math.ceil(a/d) + 1
lcm = (c*d)//(math.gcd(c, d))
dcka = math.floor(b/(lcm)) - math.ceil(a/(lcm)) + 1
print(b-a+1-cka-dka+dcka)

Submission status: Runtime Error

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

cc = B//C - A//C
dd = B//D - A//D

E = C*D//fractions.gcd(C, D)
ee = B//E - A//E

print(B - A - cc - dd + ee)

Submission status: Runtime Error

Solution code:
# 最初に入れておくとinputが早くなる
import sys
import math
input = sys.stdin.readline

a, b, c, d = map(int, input().split())
# warikireru = set()
# for i in range(b//c+1):
#    for j in range(b // d+1):
#        k = c ** i * d ** j
#        if(a <= k <= b):
#            warikireru.add(k)
# print(warikireru)
# print(b-a+1-len(warikireru))

k = c * d / math.gcd(c, d)

print(b-a-b//c+a//c-b//d+b//k+a//d-a//k)

Submission status: Runtime Error

Solution code:
A,B,C,D = [int(x) for x in input().split()]
num = list(range(A,B+1))
the_list = []
for i in num:
    if i % C != 0:
        the_list.append(i)
N = 0
for i in the_list:
    if i % D != 0:
        N += 1
print(N)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
def main():
    A,B,C,D = map(int,input().split())
    E = (C * D) // math.gcd(C,D)
    Cc = B / C
    Dd = B / D
    Ee = B / E
    flo = A-1
    Cf = flo / C
    Df = flo / D
    Ef = flo / E
    All = B-(math.floor(Cc)+math.floor(Dd)-math.floor(Ee))
    Sub = flo-(math.floor(Cf)+math.floor(Df)-math.floor(Ef))
    print(All - Sub)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = map(int, input().split())
a = a -1
e = (c * d) // math.gcd(c, d)
nc = b // c - a // c
nd = b // d - a // d
ne = b // e - a // e

print(b - a - (nc + nd - ne))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
def main():
    A,B,C,D = map(int,input().split())
    E = math.lcm(C*D)
    Cc = B / C
    Dd = B / D
    Ee = B / E
    flo = A-1
    Cf = flo / C
    Df = flo / D
    Ef = flo / E
    All = B-(math.floor(Cc)+math.floor(Dd)-math.floor(Ee))
    Sub = flo-(math.floor(Cf)+math.floor(Df)-math.floor(Ef))
    print(All - Sub)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
A,B,C,D = map(int,input().split())
if A%C==0 or B%C==0:
    C_div = (B-A+1)//C + 1
else:
    C_div = (B-A+1)//C
if B%C==0 or B%D==0:
    D_div = (B-A+1)//D + 1
else:
    D_div = (B-A+1)//D
if A%(lcm(C,D)) == 0 or B%(lcm(C,D)) == 0:
    CD_div = (B-A+1)//lcm(C,D) + 1
print((B-A+1) - C_div -D_div + CD_div)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
def main():
    A,B,C,D = map(int,input().split())
    E = math.gcd(C*D)
    Cc = B / C
    Dd = B / D
    Ee = B / E
    flo = A-1
    Cf = flo / C
    Df = flo / D
    Ef = flo / E
    All = B-(math.floor(Cc)+math.floor(Dd)-math.floor(Ee))
    Sub = flo-(math.floor(Cf)+math.floor(Df)-math.floor(Ef))
    print(All - Sub)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#未完成
import math
import numpy as np
A, B, C, D = map(int, input().split())  # aaaaa
lcmofCD = int(C * D / math.gcd(C, D))
divofAbyC = A // C
divofAbyD = A // D
divofBbyC = B // C
divofBbyD = B // D#aaaaa
divofBbylcm = B // lcmofCD
divofAbylcm = A // lcmofCD
ansofA = A - (divofAbyC + divofAbyD - divofAbylcm)
ansofB = B-(divofBbyC + divofBbyD - divofBbylcm)
ans = ansofB-ansofA

print("{}".format(ans))

Submission status: Runtime Error

Solution code:
import math

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


cn = (b//c)-(a-1)//c
dn = (b//d)-(a-1)//d
#最少公倍数
cd = (c*d)//math.gcd(c, d)
cdn = (b//cd)-(a-1)//cd

print(int(tn-cn-dn+cdn))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

a,b,c,d = map(int,input().split())
t = 0
l = b-a+1

c_count = (b // c) - ((a-1) // c)

d_count = (b // d) - ((a-1) // d)

lc = (c*d) // math.gcd(c,d)
lc_count = (b // lc) - ((a-1) // lc)

print(l-c_count-d_count+lc_count)

Submission status: Runtime Error

Solution code:
import math

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


cn = (b//c)-(a-1)//c
dn = (b//d)-(a-1)//d
#最少公倍数
cd = (c*d)//math.gcd(c, d)
cdn = (b//cd)-(a-1)//cd

print(tn-cn-dn+cdn)

Submission status: Runtime Error

Solution code:
#未完成
import math
import numpy as np
A, B, C, D = map(int, input().split())
lcmofCD = int(C * D / math.gcd(C, D))
divofAbyC = A // C
divofAbyD = A // D
divofBbyC = B // C
divofBbyD = B // D#aaaaa
divofBbylcm = B // lcmofCD
divofAbylcm = A // lcmofCD
ansofA = A - (divofAbyC + divofAbyD - divofAbylcm)
ansofB = B-(divofBbyC + divofBbyD - divofBbylcm)
ans = ansofB-ansofA

print("{}".format(ans))

Submission status: Runtime Error

Solution code:
import fractions
A,B,C,D=map(int,input().split())
X=0
L=0
M=0
N=0
E=C*D//fractions.gcd(C,D)
if B-A>=C:
    if A%C==0 or B%C==0:
        L=(B-A)//C+1
    else:
        L=(B-A)//C
else:
    if A%C==0 or B%C==0:
        L=!
    elif A%C>B%C:
        L=1
    else:
        L=0
if B-A>=D:        
    if A%D==0 or B%D==0:
        M=(B-A)//D+1
    else:
        M=(B-A)//D
else:
    if A%D==0 or B%D==0:
        M=1
    elif A%D>B%D:
        M=1
    else:
        M=0       
if B-A>=E:
    if A%E==0 or B%E==0:
        N=(B-A)//E+1
    else:
        N=(B-A)//E
else:
    if A%E==0 or B%E==0:
        N=!
    elif A%E>B%E :
        N=1
    else :
        N=0
X=B-A+1-L-M+N
print(X)

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())
t = 0
l = b-a+1

c_count = (b // c) - ((a-1) // c)

d_count = (b // d) - ((a-1) // d)

lc = lcm(c,d)
lc_count = (b // lc) - ((a-1) // lc)

print(l-c_count-d_count+lc_count)

Submission status: Runtime Error

Solution code:
import math

def main():

    # 1 <= a <= b <= 10^18
    # 1 <= c,d <= 10^9

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

    ac = -(-a // c)
    bc = b // c

    ad = -(-a // d)
    bd = b // d

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

    acd = -(-a // cd)
    bcd = b // cd

    cm_num = bc - ac + 1
    dm_num = bd - ad + 1
    cdm_num = bcd - acd + 1

    count = cm_num + dm_num - cdm_num

    total = b - a + 1

    print(total - count)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

# arr = np.linspace(A,B,1)
a1 = A // C
a2 = A // D

b1 = B // C
b2 = B // D 

ab1 = b1 - a1
ab2 = b2 - a2
if A % C == 0 and B % C == 0:
    ab1+=1
if A % D == 0 and B % D == 0:
    ab2+=1

lc = lcm(C,D)
a3 = A // lc
b3 = B // lc
ab3 = b3 - a3
res = ab1 + ab2 - ab3
print(abs(A-B)-res)

Submission status: Runtime Error

Solution code:
from sys import stdin
def gcdm(g,l):
    while(l):
        g,l=l,g%l
    return g
def mota(l,r,a):
    if r<a:
        total=0
    else:
        
        if l<a:
            first=a
        elif l>=a:
            if l%a==0:
                first=l
            else:
                first=(l//a + 1)*a
        #print(a,first)
        last=r-r%a
    
        total=((last-first)//a)+1
    return total
a,b,c,d=list(map(int,stdin.realdine().split()))
p=[c,d]
p.sort()
c,d=p[0],p[1]
total1=mota(a,b,c)

total2=mota(a,b,d)

h=(c*d)//gcdm(c,d)
total3=mota(a,b,h)
print(b-a+1-(total1+total2-total3))

Submission status: Runtime Error

Solution code:
s = input().split()
n = int(s[2])*int(s[3])
num = int(s[1])-int(s[0])
print((num*s[2])%n)

Submission status: Runtime Error

Solution code:
from math import gcd
a,b,c,d = map(int,input().split())
ans = b - a + 1#ok
a -= 1#ok

g = gcd(c,d)
temp = c*d/g
cc = -int(a/c) + int(b/c)
dd = -int(a/d) + int(b/d)
cd = -int(a/temp) + int(b / temp)

if c == 1 or d == 1:
    print(0)
else:
    print(ans - cc - dd + cd)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
count_c = 0
count_d = 0
count_cd = 0
count = 0
j = 1
g = c*d//math.gcd(c,d)
while(1):
    if c*j <= b and c*j>=a:
        count_c += 1
    if d*j <=b and d*j >= a:
        count_c += 1
    if g*j <=b and g*j >= a:
        count_cd += 1
    if c*j > b and d*j > b and g*j > b:
        break
    j += 1
s = count_c+count_d-count_cd
print(b-a +1-s)

Submission status: Runtime Error

Solution code:
from math import gcd

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

np = (B - A + 1) + (-(B - A) // C)
nq = (B - A + 1) + (-(B - A) // D)


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


npq_ = (B - A + 1) + (-(B - A) // lcm(C, D))
print(np + nq - npq_ - 1)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
count_c = 0
count_d = 0
count_cd = 0
count = 0
j = 1
g = c*d//math.gcd(c,d)
while(1)
    if c*j <= b and c*j>=a:
        count_c += 1
    if d*j <=b and d*j >= a:
        count_c += 1
    if g*j <=b and g*j >= a:
        count_cd += 1
    if c*j > b and d*j > b and g*j > b:
        break
    j += 1
s = count_c+count_d-count_cd
print(b-a +1-s)

Submission status: Runtime Error

Solution code:
import math

A, B, C, D = map(int, input().split())
CD = math.ceil(C * D / math.gcd(C, D))
AC = math.ceil(A / C)
BC = math.ceil(B / C)
C = BC - AC + 1
AD = math.ceil(A / D)
BD = math.ceil(B / D)
D = BD - AD + 1
ACD = math.ceil(A / CD)
BCD = math.ceil(B / CD)
CD = BCD - ACD + 1
print((B-A+1) - (C + D - CD))

Submission status: Runtime Error

Solution code:
import math

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


cn = b//c-(a-1)//c
dn = b//d-(a-1)//d
#最少公倍数
cd = (c*d)//math.gcd(c, d)
cdn = b//cd-(a-1)//cd

print(tn-cn-dn+cdn)

Submission status: Runtime Error

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

cA = A // C
cB = B // C
dA = A // D
dB = B // D
cdA = (A // D) // C
cdB = (B // D) // C


if ( A % C ) * (B % C) == 0:
    op=cB - cA
else:
    op=cB - cA +1
if ( A % D ) * (B % D) == 0:
    opa=dB - dA
else:
    opa=dB - dA +1

if ( A % CD ) * (B % CD) == 0:
    opaa=cdB - cdA
else:
    opaa=cdB - cdA +1   
    
print(B-A+1-op-opa+opaa)

Submission status: Runtime Error

Solution code:
#未完成
import math
import numpy as np
A, B, C, D = map(int, input().split())
lcmofCD = int(C * D / math.gcd(C, D))
divofAbyC = A // C
divofAbyD = A // D
divofBbyC = B // C
divofBbyD = B // D
divofBbylcm = B // lcmofCD
divofAbylcm = A // lcmofCD
ansofA = A - (divofAbyC + divofAbyD - divofAbylcm)
ansofB = B-(divofBbyC + divofBbyD - divofBbylcm)
ans = ansofB-ansofA

print("{}".format(ans))

Submission status: Runtime Error

Solution code:
A, B, C ,D = map(int, input().split())
count = 0
if C!= D:
    c_offset = (A-1) // C 
    c_ = B // C
    c = c_ - c_offset

    d_offset = (A-1) // D
    d_ = B // D
    d = d_- d_offset
    for i in range(C,D*C):
        if i%D ==0 | i%C==0:
        common = i
        break
    else:
        common = C*D

    cd_offset = (A-1) // common
    cd_ = B // common
    cd = cd_- cd_offset

    count = B - A - (c + d - cd) +1
else:
    c_offset = (A-1) // C 
    c_ = B // C
    c = c_ - c_offset
    
    count = B - A - c +1
print(count)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math

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

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

allnum = B - A + 1
kou = lcm(C,D)
yaku = B//C - (A-1)//C + B//D - (A-1)//D - B//kou + (A-1)//kou
print(allnum-yaku)

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())
t = 0
l = b-a+1

c_count = (b // c) - ((a-1) // c)

d_count = (b // d) - ((a-1) // d)

cd = c * d
cd_count =  (b // cd) - ((a-1) // cd)

lc = lcm(c,d)
lc_count = (b // lc) - ((a-1) // lc)

print(l-c_count-d_count+cd_count+lc)

Submission status: Runtime Error

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

s=c*d//fractions.gcd(c, d)
bk=0
ak=0
ans=0
bc=b//c
ac=a//c    
bd=b//d
ad=a//d
bsa=b//s
asa=a//s
bk=b-bc-bd+bsa
ak=a-ac-ad+asa
ans=bk-ak
if a%c!=0 or a%d!=0 or a%s!=0:
    ans+=1
elif:
  b%c==0 or b%d==0 or b%s==0
else:
  ans=ans
print(ans)

Submission status: Runtime Error

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

 #最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)
z = warareru//lcm(c,d)
print(warareru-(x+y-z))

Submission status: Runtime Error

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

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

arr = np.arange(A,B+1,1)

a1 = A // C
a2 = A // D

b1 = B // C
b2 = B // D 

ab1 = b1 - a1
ab2 = b2 - a2

if A % C  == 0 and B % C == 0:
    ab1 += 1
if A % D  == 0 and B % D == 0:
    ab2 += 1
lc = lcm(C,D)
a3 = A // lc
b3 = B // lc
ab3 = b3 - a3
res = ab1 + ab2 - ab3

print(len(arr)- res)

Submission status: Runtime Error

Solution code:
from math import ceil, floor, gcd
a, b, c, d = list(map(int, input().split()))
c0 = floor(b/c) - ceil(a/c) + 1
d0 = floor(b/d) - ceil(a/d) + 1
lcm = c * d / gcd(c,d)
lcm0 = math.floor(b/lcm) - math.ceil(a/lcm) + 1
ans = (b - a + 1) - c0 - d0 + lcm0
print(ans)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
al = b-a+1
# cで割り切れる個数
x = int(b/c) -int((a-1)/c)
# dで割り切れる個数
y = int(b/d) -int((a-1)/d)
# cdの最小公倍数
lcm_xy = int(c*d/gcd(c,d))
# cdの最小公倍数で割り切れる個数
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)
#print(x,y,xy,al)
print(al-(x+y-xy))

Submission status: Runtime Error

Solution code:
import math
def Euclidean(x,y):
    if y == 0:
        return x
    else:
        return Euclidean(y,x%y)

A,B,C,D = [int(x) for x in input().split()]
count = B - A + 1
E = Euclidean(C,D)
F = C*D/E

C_ = math.floor(B/C) - math.ceil(A/C) + 1
D_ = math.floor(B/D) - math.ceil(A/C) + 1
C_and_D = math.floor(B/F) - math.ceil(A/F) + 1
print(count - (C_ + D_ -C_and_D)):

Submission status: Runtime Error

Solution code:
A,B,C,D = [int(x) for x in input().split()]
num = range(A,B+1)
the_list = []
for i in num:
    if i % C != 0:
        the_list.append(num)
N = 0
for i in the_list:
    if i % D != 0:
        N += 1
print(N)

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
x = a
list = []
co=0
for _ in range(b-a+1):
  if a%c!=0 and a%d!=0:
    list[a] = 1
  else:
    list[a] = 0
    
  a+=1

print(sum(list))

Submission status: Runtime Error

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

a,b,c,d = map(int,input().split())
t = 0
l = b-a+1

c_count = (b // c) - ((a-1) // c)

d_count = (b // d) - ((a-1) // d)

cd = c * d
cd_count =  (b // cd) - ((a-1) // cd)

lc = lcm(c,d)
lc_count = (b // lc) - ((a-1) // lc)

print(l-c_count-d_count+cd_count+lc)

Submission status: Runtime Error

Solution code:
import math

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

ans = 0

if c % d == 0:
    print((b - a + 1) - ((b)//d - (a-1)//d))
elif d % c == 0:
    print((b - a + 1) - ((b)//c - (a-1)//c))
else:
    tot = c * d // math.gcd(c, d)
    tmp = ((b) // d - (a-1) // d) + ((b)//c - (a-1)//c) - ((b) // tot - (a-1) // tot)
    print(int((b - a + 1) - tmp))

Submission status: Runtime Error

Solution code:
import math

hoge = input().split()
a = int(hoge[0])
b = int(hoge[1])
c = int(hoge[2])
d = int(hoge[3])

hanni = b-a+1
kouyakusu = c * d / math.gcd(c, d)

print(int(hanni-(hanni/c)-(hanni/d)+(hanni/(kouyakusu))))

Submission status: Runtime Error

Solution code:
from math import gcd

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

np = (B - A + 1) + (-(B - A) // C)
nq = (B - A + 1) + (-(B - A) // D)


def coprime(a, b):
    return gcd(a, b) == 1


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


if coprime(C, D) == True:
    npq = (B - A + 1) + (-(B - A) // (C * D))
    print(np + nq - npq)
else:
    npq_ = (B - A + 1) + (-(B - A) // lcm(C, D))
    print(np + nq - npq_ - 1)

Submission status: Runtime Error

Solution code:
s = input().split()
n = s[2]*s[3]
num = s[1]-s[0]
print(num%n)

Submission status: Runtime Error

Solution code:
import fractions

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

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

def num_of_mod0(mod):
    if A%mod == 0:
        start = A
    else:
        start = (int(A/mod) +1) * mod

    end = (int(B /mod)) * mod

    return (end - start) / mod +1
if C = 1 or D =1:
    print(0)
else:
    ans =(B-A+1)-(num_of_mod0(C) + num_of_mod0(D)- num_of_mod0(lcm(C,D)))
    ans = int(ans)
    print(ans)

Submission status: Runtime Error

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

A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

count_U = B - A + 1

#count_C  = CountDivisibleNumber(C, A, B)
#print(count_C)
#count_D  = CountDivisibleNumber(D, A, B)
#print(count_D)
#count_CD = CountDivisibleNumber(lcm(C, D), A, B)
#print(count_CD)

count_C = (B // C) - (A // C)
count_D = (B // D) - (A // D)
CD = lcm(C, D)
count_CD = (B // CD) - (A // CD)

print(count_U - (count_C + count_D - count_CD))

Submission status: Runtime Error

Solution code:
import fractions
A,B,C,D=map(int,input().split())
X=0
L=0
M=0
N=0
E=C*D//fractions.gcd(C,D)
if B-A>=C:
    if A%C==0 or B%C==0:
        L=(B-A)//C+1
    else:
        L=(B-A)//C
else:
    if A%C>=B%C:
        L=1
    else:
        L=0
if B-A>=D:        
    if A%D==0 or B%D==0:
        M=(B-A)//D+1
    else:
        M=(B-A)//D
else:
    if A%D>=B%D
        M=1
    else:
        M=0       
if B-A>=E:
    if A%E==0 or B%E==0:
        N=(B-A)//E+1
    else:
        N=(B-A)//E
else:
    if A%E>=B%E :
        N=1
    else :
        N=0
X=B-A+1-L-M+N
print(X)

Submission status: Runtime Error

Solution code:
from math import gcd
a,b,c,d=map(int,input().split(' '))
r1=b-b%c
if a%c!=0:
	l1=a-a%c+c
else:
	l1=a
r2=b-b%d
if a%d!=0:
	l2=a-a%d+d
else:
	l2=a
lcm=(c*d)//gcd(c,d)
r3=b-b%lcm
if a%lcm!=0:
	l3=a-a%lcm+lcm
else:
	l3=a
nc=(r1-l1+c)//c
nd=(r2-l2+d)//d
nlcm=(r3-l3+lcm)//lcm
divi=nc+nd-nlcm
out=b-a+1
if c>a and c>b and d>a and d>b:
	print(0)
else:
	print((out-divi)%(10**9+7))

Submission status: Runtime Error

Solution code:
import fractions
a,b,c,d=map(int,input().split())
yoso=b-a+1
kobai=fractions.lcm(c,d)
AC=c-(a%c)
if AC==c:
  AC=0
BC=b%c
AD=d-(a%d)
if AD==d:
  AD=0
BD=b%d
A_kobai=a%kobai
if A_kobai==kobai:
  A_kobai=0
B_kobai=b%kobai
C=0
if AC+BC>(yoso%c):
  C=yoso//c
else:
  C=(yoso//c)+1
D=0
if AD+BD>(yoso%d):
  D=yoso//d
else:
  D=(yoso//d)+1
CD=0
if A_kobai+B_kobai>(yoso%kobai):
  CD=yoso//kobai
else:
  CD=(yoso//kobai)+1
print(yoso+CD-C-D)

Submission status: Runtime Error

Solution code:
import math

a,b,c,d = map(int,input().split())
mul = c*d//math.gcd(c,d)
sum = b//c +b//d -b//mul-a//c-a//d+a//mul
# print(a//c)
# print(sum)
if a%c==0:
    sum+=1
if a%d==0:
    sum+=1
if a%mul==0:
    sum+=1
# print(sum)
print(b+1-a-sum)

Submission status: Runtime Error

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


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

number = B - A + 1

answer_C = number // C

answer_D = number // D

answer_E = number // lcm(C,D)
final_answer = number - answer_C - answer_D + answer_E
final_answer = int(final_answer)
print(final_answer)

Submission status: Runtime Error

Solution code:
import math

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

cn = (b//c)-(a-1)//c
dn = (b//d)-(a-1)//d
cd = (c*d)//math.gcd(c, d)
cdn = (b//cd)-(a-1)//cd

print(tn-cn-dn+cdn)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
count_c = 0
count_d = 0
count_cd = 0
count = 0
j = 1
g = c*d//math.gcd(c,d)
for i in range(a,b+1):
    if c*j <= b and c*j>=a:
        count_c += 1
    if d*j <=b and d*j >= a:
        count_c += 1
    if g*j <=b and g*j >= a:
        count_cd += 1
    j += 1
s = count_c+count_d-count_cd
print(b-a +1-s)

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
al = b-a+1
# cで割り切れる個数
x = int(b/c) -int((a-1)/c)
# dで割り切れる個数
y = int(b/d) -int((a-1)/d)
# cdの最小公倍数
lcm_xy = int(c*d/math.gcd(c,d))
# cdの最小公倍数で割り切れる個数
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)
#print(x,y,xy,al)
print(al-(x+y-xy))

Submission status: Runtime Error

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

cnt = 0
s = b - a + 1
cd = (c*d) // math.gcd(c,d)

m1 = int((a-1) / c)
m2 = int((b+1) / c)
cnt += (m2-m1)

m1 = int((a-1) / d)
m2 = int((b+1) / d)
cnt += (m2-m1)

m1 = int((a-1) / cd)
m2 = int((b+1) / cd)
cnt -= (m2-m1)

#print(cnt)
print(s - cnt)

Submission status: Runtime Error

Solution code:
import math


def get_num(i):
    return int(b / i) - int((a-1) / i)


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

all_num = b - a + 1
c_num = get_num(c)
d_num = get_num(d)
lcm = int(c * d / math.gcd(c, d))
lcm_num = get_num(lcm) 

print(all_num - c_num - d_num + lcm_num)

Submission status: Runtime Error

Solution code:
import math

A,B,C,D = map(int,input().split())
total = B - A + 1

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


C_1 = B//C
C_2 = (A-1)//C
C_total = C_1 - C_2

D_1 = B//D
D_2 = (A-1)//D
D_total = D_1 - D_2

tmp_1 = B//tmp
tmp_2 = (A-1)//tmp
tmp_total = tmp_1 - tmp_2
cnt = C_total + D_total - tmp_total
print(total-cnt)

Submission status: Runtime Error

Solution code:
import math

a,b,c,d =map(int,input().split())
e = (c*d)//math.gcd(c,d)
ac = a//c   
if a % c == 0:
    ac-=1
bc = b//c 

ad=a//d 
if a % d == 0:
    ad-=1
bd= b//d


acd = a//e 
if a % e == 0:
    acd-=1
bcd= b//e 


count = b-a+1
count -= bc-ac
count -= bd-ad
count += bcd-acd

print(count)
##print(e)
#print(bcd-acd)
#print(bd-ad)
#print(bc-ac)

Submission status: Runtime Error

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

f=math.ceil(a/c) 
g=math.floor(b/c) 
h=math.ceil(a/d) 
k=math.floor(b/d) 
l=math.ceil(a/e)
m=math.floor(b/e)

if e<a:
    print(b-a+1-(g-f+1+k-h+1))
else:
    print(b-a+1-(g-f+1+k-h+1-(m-l+1)))

Submission status: Runtime Error

Solution code:
from math import gcd

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

np = (B - A + 1) + (-(B - A) // C)
nq = (B - A + 1) + (-(B - A) // D)


def coprime(a, b):
    return gcd(a, b) == 1


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


if coprime(C, D) == True:
    npq = (B - A + 1) + (-(B - A) // (C * D))
    print(np + nq - npq)
else:
    npq_ = (B - A + 1) + (-(B - A) // lcm(C, D))
    print(np + nq - npq_ - 1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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


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

number = B - A + 1

answer_C = number // C

answer_D = number // D

answer_E = number // lcm(C,D)
final_answer = number - answer_C - answer_D + answer_E
print(int(final_answer))

Submission status: Runtime Error

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

A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

count_U = B - A + 1

#count_C  = CountDivisibleNumber(C, A, B)
#print(count_C)
#count_D  = CountDivisibleNumber(D, A, B)
#print(count_D)
#count_CD = CountDivisibleNumber(lcm(C, D), A, B)
#print(count_CD)

count_C = math.floor((B // C) - (A // C))
count_D = math.floor((B // D) - (A // D))
CD = lcm(C, D)
count_CD = math.floor((B // CD) - (A // CD))

print(count_U - (count_C + count_D - count_CD))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
import fractions

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

# A以上B以下の数でXの倍数の個数
def countX(X) :
    if X > B :
        return 0
    minX = max(math.ceil(A / X),0)
    maxX = max(math.floor(B / X),0)
    return maxX - minX + 1

if C == 1 or D == 1 :
    print(0)
elif min(C,D) > B :
    print(A - B + 1)
elif max(C,D) % min(C,D) == 0 :
    Z = min(C,D)
    ans = B - A + 1 - countX(Z)
    print(ans + 1)
elif A % C == 0 and A % D == 0:
    print(z)
else :
    ans = B - A + 1

    # 最小公倍数
    Z = int(C * D / fractions.gcd(C,D))

    ans -= countX(C)
    ans -= countX(D)
    ans += countX(Z)

    print(ans)

Submission status: Runtime Error

Solution code:
A,B,C,D = [int(i) for i in input().split()] 
import numpy as np
d = np.arange(A, B+1, 1) 
d2 = filter(lambda x: (x % C != 0) and (x % D != 0), d)
print(len(list(d2)))

Submission status: Runtime Error

Solution code:
import math

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

cn = (b//c)-((a-1)//c)
dn = (b//d)-((a-1)//d)
cd = (c * d) // math.gcd(c, d)
cdn = (b//cd)-((a-1)//cd)

print(tn-cn-dn+cdn)

Submission status: Runtime Error

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


A, B, C, D = map(int, input().split())
CD = C * D // gcd(C, D)
AC = math.ceil(A / C)
BC = math.ceil(B / C)
C = math.ceilBC - AC + 1
AD = math.ceil(A / D)
BD = math.ceil(B / D)
D = BD - AD + 1
ACD = math.ceil(A / CD)
BCD = math.ceil(B / CD)
CD = BCD - ACD + 1
print((B-A+1) - (C + D - CD))

Submission status: Runtime Error

Solution code:
A, B, C, D = map(int, input().split())
CC = B // C - A // C + (A % C == 0)
DD = B // D - A // D + (A % D == 0)
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
E = lcm(C, D)
EE = B // E - A // E + (A % E == 0)
print(B - A + 1 - CC - DD + EE)