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 = map(int,input().split())
e = (c*d)//(math.gcd(c,d))
l = [c,d,e]
l2 = [0,0,0]
for i in range(0,3):
    if a%l[i] == 0:
        l2[i] = b//l[i] - a//l[i] +1
    else:
        l2[i] = b//l[i] - a//l[i]
print(b-a+1 -l2[0] -l2[1] + l2[2])

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = map(int,input().split())
e = c*d//math.gcd(c,d)
l = [c,d,e]
l2 = [0,0,0]
for i in range(0,3):
    if a%l[i] == 0:
        l2[i] = b//l[i] - a//l[i] +1
    else:
        l2[i] = b//l[i] - a//l[i]
print(b-a+1 -l2[0] -l2[1] + l2[2])

Submission status: Runtime Error

Solution code:
from math import gcd
a, b, c, d = map(int, input().split())
mc = b // c - (a-1) // c
md = b // d - (a-1) // d
mcd = b // (c*d//gcd(c, d)) - (a-1) // (c*d//gcd(c, d))

print(int((b - a + 1) - mc - md + mcd))

Submission status: Runtime Error

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

f1=math.gcd(c,d)
f2=c*d//f1

a=a-1
aa=a-a//c-a//d+a//f2
bb=b-b//c-b//d+b//f2

print(bb-aa)

Submission status: Runtime Error

Solution code:
import math

a, b, c, d = map(int, input().split())
r = 0
bc = b // c
bd = b // d
bcd = b // ((c * d) // math.gcd(c, d))
ac = -(-a // c)
ad = -(-a // d)
acd = -(-a // ((c * d) // math.gcd(c, d)))
print(b - a + 1 - bc + ac - 1 - bd + ad - 1 + bcd - acd + 1)

Submission status: Runtime Error

Solution code:
import math

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

    c_cnt = (B // C) - ((A-1) // C)
    d_cnt = (B // D) - ((A-1) // D)

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

    cd_cnt = (B // lcm) - ((A-1) // lcm)

    print(B - (A-1) - c_cnt - d_cnt + cd_cnt)


    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
import math
A,B,C,D=(int(x) for x in input().split(" "))
def gcd(x,y): 
  
   while(y): 
        x, y = y, x % y 
  
   return x 
def nb_divisers(n,m):
    return n//m
def nb_d_btw(f,g,n):
    if f%n==0:
        return nb_divisers(g,n)-nb_divisers(f,n)+1
    else:
        return nb_divisers(g,n)-nb_divisers(f,n)
def nb_notdivisers_f(a,b,c,d):
    e=int(c*d/math.gcd(c,d))
    return b-a+1-(nb_d_btw(a,b,c)+nb_d_btw(a,b,d)-nb_d_btw(a,b,e))
print(nb_notdivisers_f(A,B,C,D))

Submission status: Runtime Error

Solution code:
import math
A,B,C,D=(int(x) for x in input().split(" "))
def nb_divisers(n,m):
    return n//m
def nb_d_btw(f,g,n):
    if f%n==0:
        print(nb_divisers(g,n)-nb_divisers(f,n)+1)
        return nb_divisers(g,n)-nb_divisers(f,n)+1
    else:
        print(nb_divisers(g,n)-nb_divisers(f,n))
        return nb_divisers(g,n)-nb_divisers(f,n)
def nb_notdivisers_f(a,b,c,d):
    e=int(c*d/math.gcd(c,d))
    return b-a+1-(nb_d_btw(a,b,c)+nb_d_btw(a,b,d)-nb_d_btw(a,b,e))
print(nb_notdivisers_f(A,B,C,D))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=input().split(" ")
A=int(a)
B=int(b)
C=int(c)
D=int(d)
def nb_divisers(n,m):
    return n//m
def nb_d_btw(f,g,n):
    if f%n==0:
        print(nb_divisers(g,n)-nb_divisers(f,n)+1)
        return nb_divisers(g,n)-nb_divisers(f,n)+1
    else:
        print(nb_divisers(g,n)-nb_divisers(f,n))
        return nb_divisers(g,n)-nb_divisers(f,n)
def nb_notdivisers_f(a,b,c,d):
    e=int(c*d/math.gcd(c,d))
    return b-a+1-(nb_d_btw(a,b,c)+nb_d_btw(a,b,d)-nb_d_btw(a,b,e))
print(nb_notdivisers_f(A,B,C,D))

Submission status: Runtime Error

Solution code:
import math

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

lower = (a-1) // c + (a-1) // d - (a-1) // lcm
upper = b // c + b // d - b // lcm

print(int(b - (a-1) - (upper - lower)))

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
import sys
from math import gcd

def f(a, x):
    """1以上a以下で、xで割り切れるものの数"""
    return a // x

def lcm(a, b):
    """ aとbの最小公倍数を返す """
    return a*b // gcd(a, b)

def solve():
    A, B, C, D = list(map(int, sys.stdin.readline().split()))
    A -= 1

    # CでもDでも割り切れないもの
    b = B - f(B, C) - f(B, D) + f(B, lcm(C, D))
    a = A - f(A, C) - f(A, D) + f(A, lcm(C, D))
    print(b-a)


if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
cdg=math.gcd(c,d)
cd=c*d/cdg
ac=int(a/c)
ad=int(a/d)
acd=int(a/cd)
bc=int(b/c)
bd=int(b/d)
bcd=int(b/cd)
n=b-a+1
if a%c==0:
    cn=bc-ac+1
else:
    cn=bc-ac
if a%d==0:
    dn=bd-ad+1
else:
    dn=bd-ad
if a%(cd)==0:
    cdn=bcd-acd+1
else:
    cdn=bcd-acd
print(cd)
print(n-(cn+dn-cdn))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
gcd=math.gcd(c,d)
cd=c*d/gcd
ac=int(a/c)
ad=int(a/d)
acd=int(a/cd)
bc=int(b/c)
bd=int(b/d)
bcd=int(b/cd)
n=b-a+1
if a%c==0:
    cn=bc-ac+1
else:
    cn=bc-ac
if a%d==0:
    dn=bd-ad+1
else:
    dn=bd-ad
if a%(cd)==0:
    cdn=bcd-acd+1
else:
    cdn=bcd-acd
print(cd)
print(n-(cn+dn-cdn))

Submission status: Runtime Error

Solution code:
import fractions
a,b,c,d = map(int, input().split())
gcd = fractions.gcd(c,d)
lcm = c * d / gcd
num = [c,d,lcm]
l = b - a + 1
count = 0
temp = []

for i in range(3):
  if l - num[i] >= 0:
    count += (num[i] - 1) * (l // num[i]) + (l % num[i])
  else:
    for j in range(a,b+1):
      if j % c == 0:
        count += 1
  temp.append(count)

ans = l - (count[0] + count[1] - count[2])
print(ans)

Submission status: Runtime Error

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

import math

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

mul_c = b // c - int(math.ceil((a - 1) / c)) + 1
mul_d = b // d - int(math.ceil((a - 1) / d)) + 1

gcd_c_d = gcd(c, d)
lcm_c_d = gcd_c_d * (c / gcd_c_d) * (d / gcd_c_d)
mul_c_d = b // lcm_c_d - int(math.ceil((a - 1)) / lcm_c_d)) + 1

print(b - a + 1 - (mul_c + mul_d - mul_c_d))

Submission status: Runtime Error

Solution code:
import math

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

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

Submission status: Runtime Error

Solution code:
import math

def calcAns(n,x,y):
    print(math.gcd(x,y))
    return n - ((n//x) + (n//y) - (n//((x*y)//math.gcd(x,y))))

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

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int, input().split())
cnt=0
num_c = b//c - (a-1)//c
num_d = b//d - (a-1)//d
num_c_d = b//((c*d)//math.gcd(c,d))- (a-1)//((c*d)//math.gcd(c,d))
total = num_c + num_d - num_c_d
print(int((b-a+1) - total))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int, input().split())
cnt=0
num_c = b//c - (a-1)//c
num_d = b//d - (a-1)//d
num_c_d = b//((c*d)/math.gcd(c,d))- (a-1)//((c*d)/math.gcd(c,d))
total = num_c + num_d - num_c_d
print(int((b-a+1) - total))

Submission status: Runtime Error

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

print(int(num_divb)+int(num_diva))

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

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

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

Submission status: Runtime Error

Solution code:
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
A, B, C, D = (int(a) for a in input().split())
a = B - A + 1
b = abs(B // C - (A - 1) // C)
c = abs(B // D - (A - 1) // D)
d = abs(B // (C * D) - (A - 1) // (lcm(C, D)))
print(a - (b + c - d))

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))

n = B - A + 1
cn = B // C - (A - 1) // C
dn = B // D - (A - 1) // D
cdn = B // lcm(C, D) - (A - 1) // lcm(C, D)

ans = n - (cn + dn - cdn)
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

a -= 1
cd = (c * d) // math.gcd(c, d)

a_d_c = a // c
b_d_c = b // c

a_d_d = a // d
b_d_d = b // d

a_d_cd = a // cd
b_d_cd = b // cd

b_d = b_d_c + b_d_d - b_d_cd
a_d = a_d_c + a_d_d - a_d_cd

ans =  b - b_d - a + a_d

print(ans)

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-=1

AC=int(A/C)
AD=int(A/D)
BC=int(B/C)
BD=int(B/D)
ACD=int(A/lcm(C,D))
BCD=int(B/lcm(C,D))
A_=AC+AD-ACD
B_=BC+BD-BCD

print((B-B_)-(A-A_))

Submission status: Runtime Error

Solution code:
def f_c():
    import math
    a, b, c, d = map(int, input().split())
    c_n = b//c-a//c+1 if a%c==0 else b//c-a//c
    d_n = b//d-a//d+1 if a%d==0 else b//d-a//d
    cd = c*d//math.gcd(c, d)
    cd_n = b//cd-a//cd+1 if a%cd==0 else b//cd-a//cd
    print(b-a+1-(c_n+d_n-cd_n))

if __name__ == "__main__":
    f_c()

Submission status: Runtime Error

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

n_all = b - a
n_c = int(n_all / c)
n_d = int(n_all / d)
n_lcm = int(n_all / lcm)

ans = n_all - (n_c + n_d - n_lcm)
print(ans)

Submission status: Runtime Error

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

icm = C*D / fractions.gcd(C,D)
ans = (B - A + 1)
if A != B:
    if A % C == 0:
        ans -= int(B // C - A // C) + 1
    else:
        ans -= int(B // C - A // C)
    if A % D == 0:
        ans -= int(B // D - A // D) + 1
    else:
        ans -= int(B // D - A // D)

    if A % icm == 0:
        ans += int(B // icm - A // icm) + 1
    else:
        ans += int(B // icm - A // icm)
	print(int(ans))
else:
    if A % C == 0 or A % D == 0:
        print(0)
    else:
        print(1)

Submission status: Runtime Error

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

icm = C*D / math.gcd(C,D)
ans = (B - A + 1)
if A % C == 0:
    ans -= (B // C - A // C) - 1
else:
    ans -= (B // C - A // C)
if A % D == 0:
    ans -= (B // D - A // D) - 1
else:
    ans -= (B // D - A // D)

if A % icm == 0:
    ans += (B // icm - A // icm) - 1
else:
    ans += (B // icm - A // icm)

print(int(ans))

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = [int(i) for i in input().split()]
def lcm(a,b):
    return a*b//math.gcd(a,b)
lcm = lcm(C,D)
aa = ((B//C)-(1 if A%C != 0 else 0))-(A//C)+1
bb = ((B//D)-(1 if A%D != 0 else 0))-(A//D)+1
ll = ((B//lcm)-(1 if A%lcm != 0 else 0))-(A//lcm)+1
print(int((B-A+1)-(aa+bb-ll)))

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = [int(i) for i in input().split()]
def lcm(a,b):
    return a*b/math.gcd(a,b)
lcm = lcm(C,D)
aa = ((B//C)-(1 if A%C != 0 else 0))-(A//C)+1
bb = ((B//D)-(1 if A%D != 0 else 0))-(A//D)+1
ll = ((B//lcm)-(1 if A%lcm != 0 else 0))-(A//lcm)+1
print(int((B-A+1)-(aa+bb-ll)))

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = [int(i) for i in input().split()]
def lcm(a,b):
    return a*b/math.gcd(a,b)
lcm = lcm(C,D)
aa = ((B//C)+(1 if A%C == 0 else 0))-(A//C)
bb = ((B//D)+(1 if A%D == 0 else 0))-(A//D)
ll = ((B//lcm)+(1 if A%lcm == 0 else 0))-(A//lcm)
print(int((B-A+1)-(aa+bb-ll)))

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = [int(i) for i in input().split()]
ii = 1
ee = 1
dd = 0
for i in range(A,B+1):
    if i % C == 0:
        z = i
        break
for i in range(A,B+1):
    if i % D == 0:
        v = i
        break
rr = z
while rr < B:
    rr += C
    ii += 1
ll = v
while ll < B:
    ll += C
    ee += 1
    if ll % (C*D) == 0:
        dd += 1
print(int((B-A+4)-(ii+ee-dd)))

Submission status: Runtime Error

Solution code:
#まだ自信をもっと答えられないんだよな
#掛け算じゃなくて最小公倍数や
#デバッグの後消す
import math
a,b,c,d=[int(i) for i in input().split()]
c1=b//c-a//c
if a%c==0:
    c1+=1
d1=b//d-a//d
if a%d==0:
    d1+=1
cd1=b//(c*d//math.gcd(c,d))-a//(c*d//math.gcd(c,d))
if a%(c*d)==0:
    cd1+=1
#print(c1)
#print(d1)
#print(cd1)
print(b-a+1-c1-d1+cd1)

Submission status: Runtime Error

Solution code:
#まだ自信をもっと答えられないんだよな
#掛け算じゃなくて最小公倍数や
import math
a,b,c,d=[int(i) for i in input().split()]
c1=b//c-a//c
if a%c==0:
    c1+=1
d1=b//d-a//d
if a%d==0:
    d1+=1
cd1=b//(c*d//math.gcd(c,d))-a//(c*d//math.gcd(c,d))
if a%(c*d)==0:
    cd1+=1
print(c1)
print(d1)
print(cd1)
print(b-a+1-c1-d1+cd1)

Submission status: Runtime Error

Solution code:
import math

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

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

if A%C == 0:
    C_div = B//C - A//C + 1
else:
    C_div = B//C - A//C

if A%D == 0:
    D_div = B//D - A//D + 1
else:
    D_div = B//D- A//D


if A%E == 0:
    CandD_div  = B//E - A//E + 1
else:
    CandD_div  = B//E- A//E


ans = B - A + 1 - (C_div + D_div - CandD_div)
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

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

if A%C == 0:
    C_div = B//C - A//C + 1
else:
    C_div = B//C - A//C

if A%D == 0:
    D_div = B//D - A//D + 1
else:
    D_div = B//D- A//D


if A%E == 0:
    CandD_div  = B//E - A//E + 1
else:
    CandD_div  = B//E- A//E


ans = B - A + 1 - (C_div + D_div - CandD_div)
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

E =int(C*D/math.gcd(C,D))

if A%C == 0:
    C_div = B//C - A//C + 1
else:
    C_div = B//C - A//C

if A%D == 0:
    D_div = B//D - A//D + 1
else:
    D_div = B//D- A//D


if A%E == 0:
    CandD_div  = B//E - A//E + 1
else:
    CandD_div  = B//E- A//E


ans = B - A + 1 - (C_div + D_div - CandD_div)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def f(num, c, d):
    return num - (num // c + num // d - num // int(c * d / np.gcd(c, d)))

print (f(B, C, D) - f(A - 1, C, D))

Submission status: Runtime Error

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

def f(num, c, d):
    return num - (num // c + num // d - num // int(c * d / math.gcd(c, d)))

print (f(B, C, D) - f(A - 1, C, D))

Submission status: Runtime Error

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

dc = math.floor(B/C) - math.floor((A-1)/C)
dd = math.floor(B/D) - math.floor((A-1)/D)
lcmCD = (C*D)/math.gcd(C,D)
dcd = math.floor(B/lcmCD) - math.floor((A-1)/lcmCD)

print(B-A+1 - (dc + dd - dcd))

Submission status: Runtime Error

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

dc = math.floor(B/C) - math.floor((A-1)/C)
dd = math.floor(B/D) - math.floor((A-1)/D)
lcmCD = (C*D)/math.gcd(C,D)
dcd = math.floor(B/lcmCD) - math.floor((A-1)/lcmCD)

print(B-A+1 - (dc + dd - dcd))

Submission status: Runtime Error

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

import math
def CntMultiples(a, b, n):
    return b//n - a//n + int(a%n==0)

Submission status: Runtime Error

Solution code:
import math

def CntMultiples(a, b, n):
    return b//n - a//n + int(a%n==0)

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

Submission status: Runtime Error

Solution code:
# 最大公約数gcd, 
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

# 最小公倍数lcm
def lcm(a, b):
    return (a*b) // gcd(a,b)

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

cd = lcm(c,d)
r = b-a+1

min_c = math.ceil(a/c)
max_c = math.floor(b/c)
min_d = math.ceil(a/d)
max_d = math.floor(b/d)
min_cd = math.ceil(a/cd)
max_cd = math.floor(b/cd)

c_num = max_c-min_c+1
d_num = max_d-min_d+1
cd_num = max_cd-min_cd+1

print(r-c_num-d_num+cd_num)

Submission status: Runtime Error

Solution code:
import math

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

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

min_c = math.ceil(a/c)
max_c = math.floor(b/c)
min_d = math.ceil(a/d)
max_d = math.floor(b/d)
min_cd = math.ceil(a/cd)
max_cd = math.floor(b/cd)

c_num = max_c-min_c+1
d_num = max_d-min_d+1
cd_num = max_cd-min_cd+1

print(r-c_num-d_num+cd_num)

Submission status: Runtime Error

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

#A, Bの公約数 (gcd(C,D)), 公倍数
from math import gcd
LCM = C * D / gcd(C,D)
    
# B以下でCでもDでも割り切れない数
Ans_B = B - (B//C + B//D - B//LCM)
# A未満でCでもDでも割り切れない数
Ans_A = A-1 - ((A-1)//C + (A-1)//D  - (A-1)//LCM) 
    
print(int(Ans_B - Ans_A))

Submission status: Runtime Error

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

def f(x, y, z):
    cnt = y // z - x // z
    if x % z == 0:
        cnt += 1
    return cnt

div_c_count = f(a, b, c)
div_d_count = f(a, b, d)

import math
lcm = c * d // math.gcd(c, d)
cm_count = f(a, b, lcm)

print(all_count - (div_c_count + div_d_count - cm_count))

Submission status: Runtime Error

Solution code:
from math import gcd


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


def counter(n, a):
    return n // a


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

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((B - (B // C + B // D - B // E))-((A-1)-((A-1) // C + (A-1) // D - (A-1) // E)))

Submission status: Runtime Error

Solution code:
import sys
 import copy
 
 sys.setrecursionlimit(1000000)
 
 
 # input = sys.stdin.readline
 
 # ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~
 
 def GCD(x, y):
     return x if y == 0 else GCD(y, x % y)
 
 
 def LCM(x, y):
     return x // GCD(x, y) * y
 
 
 A, B, C, D = map(int, input().split())
 
 S = B - A + 1
 
 canC = B // C - (A - 1) // C
 canD = B // D - (A - 1) // D
 canCD = B // LCM(C, D) - (A - 1) // LCM(C, D)
 
 print(S - (canC + canD) + canCD)

Submission status: Runtime Error

Solution code:
import math
import copy
# import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

num = getInputListInt()

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

c_modzero = math.floor(b/c) - math.floor((a-1)/c)
d_modzero = math.floor(b/d) - math.floor((a-1)/d)

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

cd_modzero = math.floor(b/(cd)) - math.floor((a-1)/(cd))

ans = b - a + 1 - (c_modzero + d_modzero - cd_modzero)

print(ans)

Submission status: Runtime Error

Solution code:
import math
import copy
# import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

num = getInputListInt()

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

c_modzero = math.floor(b/c) - math.floor((a-1)/c)
d_modzero = math.floor(b/d) - math.floor((a-1)/d)

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

cd_modzero = math.floor(b/(cd)) - math.floor((a-1)/(cd))

ans = b - a + 1\
      - (c_modzero + d_modzero - cd_modzero)

print(ans)

Submission status: Runtime Error

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

def cont(x):
    cnt1 = x//c 
    cnt2 = x//d
    ans = x - cnt1 - cnt2 + x//lcm
    return int(ans)

print(cont(b) - cont(a-1))

Submission status: Runtime Error

Solution code:
a, b = map(int, input().split())
c, d = map(int, input().split())
lst = []
cnt = 0
for i in range(a, b+1):
    if i%c != 0:
        lst.append(i)
for j in lst:
    if j%d != 0:
        cnt += 1
print(cnt)

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])

E = int((C * D) / math.gcd(C, D))

X = int(B/C)-int((A-1)/C)
Y = int(B/D)-int((A-1)/D)
Z = int(B/E)-int((A-1)/E)

print(B-A+1-X-Y+Z)

Submission status: Runtime Error

Solution code:

import math

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

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

X = (B//C)-((A-1)//C)
Y = (B//D)-((A-1)//D)
Z = (B//E)-((A-1)//E)

print(B-A+1-X-Y+Z)

Submission status: Runtime Error

Solution code:

import math

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

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

X = (B//C)-((A-1)//C)
Y = (B//D)-((A-1)//D)
Z = (B//E)-((A-1)//E)

print(B-A+1-X-Y+Z)

Submission status: Runtime Error

Solution code:

import math

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

E = int((C * D) / math.gcd(C, D))

X = (B//C)-((A-1)//C)
Y = (B//D)-((A-1)//D)
Z = (B//E)-((A-1)//E)

print(int(B-A+1-X-Y+Z))

Submission status: Runtime Error

Solution code:
import math

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

E = int((C * D) / math.gcd(C, D))

X = (B//C)-(A-1//C)
Y = (B//D)-(A-1//D)
Z = (B//(E))-(A-1//(E))

print(int(B-A+1-X-Y+Z))

Submission status: Runtime Error

Solution code:
import sys
import collections
import copy
import math

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

E = (C * D) / math.gcd(C, D)
X = math.floor(B/C) - math.floor(A/C)
Y = math.floor(B/D) - math.floor(A/D)
Z = math.floor(B/E) - math.floor(A/E)

print(int(B-A-X-Y+Z))

Submission status: Runtime Error

Solution code:
import math

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

E = (C * D) / math.gcd(C, D)
X = math.floor(B/C) - math.floor(A/C)
Y = math.floor(B/D) - math.floor(A/D)
Z = math.floor(B/E) - math.floor(A/E)

print(int(B-A-X-Y+Z))

Submission status: Runtime Error

Solution code:

import math

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

E = int((C * D) / math.gcd(C, D))
X = math.floor(B/C) - math.floor(A/C)
Y = math.floor(B/D) - math.floor(A/D)
Z = math.floor(B/E) - math.floor(A/E)

print(int(B-A-X-Y+Z))

Submission status: Runtime Error

Solution code:

import math

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

E = int((C * D) / math.gcd(C, D))
X = (B//C)-(A//C)
Y = (B//D)-(A//D)
Z = (B//E)-(A//E)+1

print(int(B-A-X-Y+Z))

Submission status: Runtime Error

Solution code:
import math

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

E = int((C * D) / math.gcd(C, D))
X = (B//C)-(A//C)
Y = (B//D)-(A//D)
Z = (B//E)-(A//E)

print(int(B-A-X-Y+Z))

Submission status: Runtime Error

Solution code:

import math

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

E = C * D / math.gcd(C, D)
X = (B//C)-(A//C)
Y = (B//D)-(A//D)
Z = (B//(E))-(A//(E))+1

print(int(B-A-X-Y+Z))

Submission status: Runtime Error

Solution code:
import math

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

CD = C * D / math.gcd(C, D)
X = (B//C)-(A//C)
Y = (B//D)-(A//D)
Z = (B//(CD))-(A//(CD))+1

print(B-A-X-Y+Z)

Submission status: Runtime Error

Solution code:
import math

A,B,C,D = map(int, input().split())
lcm = C * D // math.gcd(C, D)
tmp = (B // C - (A - 1) // C) + (B // D - (A - 1) // D) - (B // lcm - A // lcm)
output = B - A + 1 - tmp

print(output)

Submission status: Runtime Error

Solution code:
import math

def lcm(a, b):
    y = a*b / math.gcd(a, b)
    return int(y)

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

A -= 1

lcm_cd = lcm(C, D)
a_by_c = A // C
a_by_d = A // D
b_by_c = B // C
b_by_d = B // D
a_by_cd = A // lcm_cd
b_by_cd = B // lcm_cd

toB = B - (b_by_c + b_by_d - b_by_cd)
toA = A - (a_by_c + a_by_d - a_by_cd)

print(toB - toA)

Submission status: Runtime Error

Solution code:
import math

A,B,C,D=map(int,input().split())
CD = C*D/math.gcd(C,D)

def S(A,B,X):
    A = A if A%X==0 else A+(X-A%X)
    if B>A:
        return int((B-A)//X+1)
    else:
        return 0

print(B-A+1-(S(A,B,C)+S(A,B,D)-S(A,B,CD)))

Submission status: Runtime Error

Solution code:
import sys
import math
from fractions import gcd

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

c1 = b // c - (a - 1) // c
d1 = b // d - (a - 1) // d
cd = (c * d) //math.gcd(c,d)
cd1 = b // cd - (a - 1) // cd



print((b - a + 1) - c1 - d1 + cd1)

Submission status: Runtime Error

Solution code:
import sys
import math

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

c1 = b // c - (a - 1) // c
d1 = b // d - (a - 1) // d
cd = (c * d) //math.gcd(c,d)
cd1 = b // cd - (a - 1) // cd


print((b - a + 1) - c1 - d1 + cd1)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
cd = (c*d) // math.gcd(c,d)
c_sum = (b // c) - ((a-1) // c)
d_sum = (b // d) - ((a-1) // d)
cd_sum = (b // cd) - ((a-1) // cd)
result = b-a+1 -(c_sum+d_sum-cd_sum)
print(result)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
cd = (c*d) // (max(math.gcd(c,d),1))
c_sum = (b // c) - ((a-1) // c)
d_sum = (b // d) - ((a-1) // d)
cd_sum = (b // cd) - ((a-1) // cd)

result = b-a+1 -(c_sum+d_sum-cd_sum)
print(result)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
cd = (c*d) // (math.gcd(c,d))
c_sum = (b // c) - ((a-1) // c)
d_sum = (b // d) - ((a-1) // d)
cd_sum = (b // cd) - ((a-1) // cd)

result = b-a+1 -(c_sum+d_sum-cd_sum)
print(result)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
cd = (c*d) // math.gcd(c,d)
c_sum = (b // c) - ((a-1) // c)
d_sum = (b // d) - ((a-1) // d)
cd_sum = (b // cd) - ((a-1) // cd)
 
result = b-a+1 -(c_sum+d_sum-cd_sum)
print((result))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
cd = (c*d) // math.gcd(c,d)
c_sum = (b // c) - ((a-1) // c)
d_sum = (b // d) - ((a-1) // d)
cd_sum = (b // cd) - ((a-1) // cd)

result = b-a+1 -(c_sum+d_sum-cd_sum)
print((result))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
cd = (c*d) // math.gcd(c,d)
c_sum = (b // c) - ((a-1) // c)
d_sum = (b // d) - ((a-1) // d)
cd_sum = (b // cd) - ((a-1) // cd)

result = b-a+1 -(c_sum+d_sum-cd_sum)
print((result)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
cd = (c*d) // math.gcd(c,d)
print(cd)
c_sum = (b // c) - ((a-1) // c)
d_sum = (b // d) - ((a-1) // d)
cd_sum = (b // cd) - ((a-1) // cd)

result = b-a+1 -(c_sum+d_sum-cd_sum)
print((result))

Submission status: Runtime Error

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

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

b_c = b//c
b_d = b//d
b_e = b//e
a_c = (a-1)//c
a_d = (a-1)//d
a_e = (a-1)//e

print(b-a+1 - (b_c - a_c) - (b_d - a_d) + (b_e - a_e))

Submission status: Runtime Error

Solution code:
import math

A, B, C, D=map(int, input().split())
x=math.gcd(C, D)
p=B//C-(A-1)//C
q=B//D-(A-1)//D
r=B//x-(A-1)//x
print(B-(A-1)-(p+q-r))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = map(int, input().split())
m=0
e = c * d/math.gcd(c,d)
num_c = int(b/c)-int((a-1)/c)
num_d = int(b/d)-int((a-1)/d)
num_e = int(b/e)-int((a-1)/e)
m = num_c + num_d - num_e
print(b-a+1-m)

Submission status: Runtime Error

Solution code:
import fraction
a, b, c, d = map(int, input().split())
m=0
e = c * d/fraction.gcd(c,d)
num_c = int(b/c)-int((a-1)/c)
num_d = int(b/d)-int((a-1)/d)
num_e = int(b/e)-int((a-1)/e)
m = num_c + num_d - num_e
print(b-a+1-m)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

def calc(x):
    return x-(x//c)-(x//d)+(x//lcm)

print(calc(b)-calc(a-1))

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
def gcd(x,y):
  while y!=0:
    x,y=y,x%y
  return x
C=((b-a+1)//c)+1
D=((b-a+1)//d)+1
CD=((b-a+1)//gcd(c,d if c>d else d,c))+1
print(b-a+1-C-D+CD)

Submission status: Runtime Error

Solution code:
from fraction import gcd

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

def f(a, b, n):
  return b // n - (a - 1) // n

acc = 0
acc += f(a, b, c)
acc += f(a, b, d)
acc -= f(a, b, c * d // gcd(c, d))
print(b - a + 1 - acc)

Submission status: Runtime Error

Solution code:
import math

def main():
    A, B, C, D = map(int, input().split())
    p = math.gcd(C, D)
    lcm = C * D // p
    dA = (A-1) - (A-1) // C - (A-1) // D + (A-1) // lcm
    dB = B - B // C - B // D + B // lcm
    return dB - dA


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

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = map(int,input().split())
bi = C*D/math.gcd(D,C)
A-=1
Bbi =B//bi
Abi =A//bi
sa = Bbi -Abi
Bc = B//C
Bd = B//D
Ac = A//C
Ad = A//D
print(int( B-A - ((Bc-Ac) + (Bd-Ad) - sa)  ))