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:
a,b,c,d=map(int,input().split())
from fractions import gcd
lcm=(c*d)/gcd(c,d)
n=(b//c)-((a-1)//c)
n+=(b//d)-((a-1)//d)
print(b-a+1-n+((b//lcm)-((a-1)//lcm))

Submission status: Runtime Error

Solution code:
from fractions import gcd 

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

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

f = B//C - (A-1)//C
f = f+(B//D - (A-1)//D)
ans = B-A+1-f + B//E-(A-1)//E
print(ans)

Submission status: Runtime Error

Solution code:
import fractions

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

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

f = B//C - (A-1)//C
f = f+(B//D - (A-1)//D)
ans = B-A+1-f + B//E-(A-1)//E
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

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

f = B//C - (A-1)//C
f = f+(B//D - (A-1)//D)
ans = B-A+1-f + B//E-(A-1)//E
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

def f(X, C, D):
    return int(X // C) + int(X // D) - int(X // ((C * D ) / math.gcd(C, D)))

ans = int((B - A + 1) - f(B, C, D) + f(A, C, D))

print(ans)

Submission status: Runtime Error

Solution code:
import math


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


if __name__ == "__main__":
    a, b, c, d = map(int, input().split())
    cnt_ac, cnt_bc = int((a-1)/c), int(b/c)
    cnt_ad, cnt_bd = int((a-1)/d), int(b/d)
    cnt_acd, cnt_bcd = int(a/lcm(c,d)), int(b/lcm(c,d))
    print((cnt_bc-cnt_ac), (cnt_bd-cnt_ad), (cnt_bcd-cnt_acd))
    print((b-a+1) - ((cnt_bc-cnt_ac)+(cnt_bd-cnt_ad)-(cnt_bcd-cnt_acd)))

Submission status: Runtime Error

Solution code:
# def gcd(n,m):
#     if m == 0:
#         return n
#     else:
#         x = max(n,m)%min(n,m)
#         while x != 0:
#             return gcd(m,x)
#         else:
#             return m

import math
import copy

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

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

f = B//C - (A-1)//C
f = f+(B//D - (A-1)//D)
ans = B-A+1-f + B//E-(A-1)//E
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

def f(X, C, D):
    return int(X // C) + int(X // D) - int(X // ((C * D ) / math.gcd(C, D)))

ans = int((B - A + 1) - f(B, C, D) + f(A, C, D))

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

Submission status: Runtime Error

Solution code:
import math
A,B,C,D  = map(int, input().split())
#Cの倍数
if A % C ==0:
    C_start = A // C
else:
    C_start = (A//C)+1

C_end = B//C
C_count =-C_start+C_end+1

#Dの倍数
if A % D ==0:
    D_start = A // D
else:
    D_start = (A//D)+1

D_end = B//D
D_count =-D_start+D_end+1

#CとDの倍数
CD=C*D//math.gcd(C, D)
if A % CD ==0:
    CD_start = A // CD
else:
    CD_start = (A//CD)+1

CD_end = B//CD
CD_count =-CD_start+CD_end+1

count = (B-A+1)-(C_count +D_count -CD_count)
print(count)

Submission status: Runtime Error

Solution code:
import math
import copy

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

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

f = B//C - (A-1)//C
f = f+(B//D - (A-1)//D)
ans = B-A+1-f + B//E-(A-1)//E
print(ans)

Submission status: Runtime Error

Solution code:
def gcd(n,m):
    if m == 0:
        return n
    else:
        x = max(n,m)%min(n,m)
        while x != 0:
            return gcd(m,x)
        else:
            return m

import math
import copy

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

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

f = B//C - (A-1)//C
f = f+(B//D - (A-1)//D)
ans = B-A+1-f + B//E-(A-1)//E
print(ans)

Submission status: Runtime Error

Solution code:
s = input().split()
A = s[0]
B = s[1]
C = s[2]
D = s[3]
k = 0
for i in range(A,B+1):
  if i%C != 0 and i%D != 0:
    k = k + 1
print(k)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
a-=1
l=c//math.gcd(c,d)*d
print(b-a-b//c+a//c-b//d+a//d+b//l-a//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())

a = int(B/C) - int((A-1)/C)
b = int(B/D) - int((A-1)/D)
c = int(B/lcm(C,D)) - int((A-1)/lcm(C, D))

print ( B - (A - 1) - (a + b - c))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if A%C==0:
    Cst=A//C
else:
    Cst=A//C+1
Cen=B//C

if A%D==0:
    Dst=A//D
else:
    Dst=A//D+1
Den=B//D
if C==D:
    andD=0
else:
    andD=Den-Dst+1

if A%(C*D)==0):
    CDst=A//(C*D)
else:
    CDst=A//(C*D)+1
CDen=B//(C*D)
if C*D>B:
    andnm=0
else:
    andnm=CDen-CDst+1
print(B-A+1-(Cen-Cst+1)-andD+andnm)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

def Lcm(a,b):
    return int(a*b/math.gcd(a,b))
def Kosu(min,max,k):
    if(min%k==0):
        tyousei=1
    return int(max/k)-int((min-1)/k)

min,max,a,b=map(int,input().split())
c=Lcm(a,b)
print(max+1-min-Kosu(min,max,a)-Kosu(min,max,b)+Kosu(min,max,c))

Submission status: Runtime Error

Solution code:
from concurrent.futures import ThreadPoolExecutor
a, b, c, d = map(int, input().split())


def y(i):
    return bool(i % c and i % d)
with ThreadPoolExecutor() as executor:
    ans = executor.map(y, range(a, b + 1))
print(sum(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:
a, b, c, d = map(int, input().split())


ans = map(y, range(a, b + 1))
print(sum(ans))

Submission status: Runtime Error

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

if C == 1 and D != 1 :
  print(0)
elif D == 1 and C != 1 :
  print(1)
else :
  print(z)

Submission status: Runtime Error

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

async def y(i):
    return bool(i % c and i % d)

ans = (
    loop.run_until_complete(
        asyncio.gather(*(y(i) for i in range(a, b + 1)))
    )
)
print(sum(ans))

Submission status: Runtime Error

Solution code:
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
lc = (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:
A , B , C , D = map(int,input().split())

if C == 1 and D == 1 :
  print(0)
else :
  print(z)

Submission status: Runtime Error

Solution code:
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
lc = (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:
def main():
    N = int(input())
    tasks = [tuple(map(int, input().split())) for _ in range(N)]
    tasks.sort(key=lambda x: x[1])
    time = 0
    for A, B in tasks:
        time += A
        if B < time:
            return 'No'
    return 'Yes'

print(main())

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 = (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
import fractions

A, B, C, D = map(int, input().split())
E = (C * D) // fractions.gcd(C, D)
count_div = 0

n_ = (A-1) // C
n = math.ceil(A / C) - 1
m = B // C
if m >= n:
  count_div += m - n

l_ = (A-1) // D
l = math.ceil(A / D) - 1
k = B // D
if k >= l:
  count_div += k - l

j_ = (A-1) // E
j = math.ceil(A / E) - 1
i = B // E
if i >= j:
  count_div -= i - j

if (n_ != n) or (l_ != l) or (j_ != j):
  sleep(2)
else:
  print(B - A + 1 - count_div)

Submission status: Runtime Error

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

if a%d == 0:
  dd += b//d - a/d + 1
else:
  dd += b//d - a/d

if a%cd == 0:
  cd += b//cd - a/cd + 1
else:
  cd += b//cd - a/cd    

print(cc+dd-cd)

Submission status: Runtime Error

Solution code:
import math
import fractions

# 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

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

if C == 1 :
  print(z)

ans = B - A + 1

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

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

print(int(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())

x = int(lcm(c, d))

A = a-1 - (a - 1) // c - (a - 1) // d + (a - 1) // x
B = b - b // c - b // d + b // x

print(int(B - A))

Submission status: Runtime Error

Solution code:
import math
import fractions

# 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

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

if D == 1 :
  print(z)

ans = B - A + 1

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

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

print(int(ans))

Submission status: Runtime Error

Solution code:
import math
import fractions

# 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 D == 1 :
  print(z)

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

ans = B - A + 1

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

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

print(int(ans))

Submission status: Runtime Error

Solution code:
import math
import fractions

# 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

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

if D == 1 :
  print(0)
else :
  ans = B - A + 1

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

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

print(int(ans))

Submission status: Runtime Error

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

async def y(i):
    return not(i % c or i % d)

ans = sum(
    loop.run_until_complete(
        asyncio.gather(*(y(i) for i in range(a, b + 1)))
    )
)
print(ans)

Submission status: Runtime Error

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

print(main())

Submission status: Runtime Error

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

if a < 0 or b < 0 or c < 0 or d < 0:
  print(a, b, c, d)

Submission status: Runtime Error

Solution code:
import math
from fractions import gcd
a, b, c, d = [int(x) for x in inputs[0].split(' ')]
e = c * d // gcd(c, d) # lcm(c, d)

num_b = b - b // c - b // d + b // e
num_a = (a-1) - (a-1) // c - (a-1) // d + (a-1) // e

print(num_b - num_a)

Submission status: Runtime Error

Solution code:
#c.py
from math import gcd
def lcm(a, b):
    return a * b // gcd(a,b)
a,b,c,d = map(int,input().split())
canC = b//c -(a-1)//c
canD = b//d - (a-1)//d
dbCD = b//lcm(c,d) -(a-1)//lcm(c,d)
print((b-a+1) -canC - canD + dbCD)

Submission status: Runtime Error

Solution code:
import math

def Lcm(a,b):
    return a*b//math.gcd(a,b)
def Kosu(min,max,k):
    return max//k-(min-1)//k

min,max,a,b=map(int,input().split())
c=Lcm(a,b)
print(max+1-min-Kosu(min,max,a)-Kosu(min,max,b)+Kosu(min,max,c))

Submission status: Runtime Error

Solution code:
import fractions

def f(x, c, d):
    lcm_num = c*d / fractions.gcd(c, d)
    return x - x//c - x//d + x//lcm_num

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

print(f(b) - f(a-1))

Submission status: Runtime Error

Solution code:
import math

def f(x, c, d):
    lcm_num = c*d / math.gcd(c, d)
    return x - x//c - x//d + x//lcm_num

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

print(f(b) - f(a-1))

Submission status: Runtime Error

Solution code:
import math

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

c_min = int(a/c) if a % c == 0 else int(a/c) + 1
c_max = int(b/c)
delta_c = c_max - c_min + 1

d_min = int(a/d) if a % c == 0 else int(a/d) + 1
d_max = int(b/d)
delta_d = d_max - d_min + 1

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

cd = lcm(c, d)
cd_min = int(a/cd) if a % c == 0 else int(a/cd) + 1
cd_max = int(b/cd)
delta_cd = cd_max -cd_min + 1

num_cd = delta_c + delta_d - delta_cd
print( b-a+1 - num_cd, end='')

Submission status: Runtime Error

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

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

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

print(al-(x+y-xy))

Submission status: Runtime Error

Solution code:
import math

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

def f(x):
    return x - x//c - x//d + x//lcm_num

print(f(b) - f(a-1))

Submission status: Runtime Error

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

def f(x):
    return x - x//c - x//d + x//lcm_num

print(f(b) - f(a-1))

Submission status: Runtime Error

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

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

s=(b-a-(b//c-((a-1)//c + 1))-(b//d - ((a-1)//d + 1))+(b//cd-((a-1)//cd + 1)))
print(s)

Submission status: Runtime Error

Solution code:
# a から bで　cでもdでも割り切れないものの数を調べる
import math

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

c_min = int(a/c) if a % c == 0 else int(a/c) + 1
c_max = int(b/c)
delta_c = c_max - c_min + 1

d_min = int(a/d) if a % c == 0 else int(a/d) + 1
d_max = int(b/d)
delta_d = d_max - d_min + 1

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

cd = lcm(c, d)
cd_min = int(a/cd) if a % c == 0 else int(a/cd) + 1
cd_max = int(b/cd)
delta_cd = cd_max -cd_min + 1

# cとdで割り切れる数
num_cd = delta_c + delta_d - delta_cd
print( b-a+1 - num_cd, end='')

Submission status: Runtime Error

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

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

s=B - A + 1 - (((B//C - (A-1)//C))+(B//D - (A-1)//D)-(B//l)-((A-1)//l))
print(s)

Submission status: Runtime Error

Solution code:
# a から bで　cでもdでも割り切れないものの数を調べる
import math

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

c_min = int(a/c) if a % c == 0 else int(a/c) + 1
c_max = int(b/c)
delta_c = c_max - c_min + 1

d_min = int(a/d) if a % c == 0 else int(a/d) + 1
d_max = int(b/d)
delta_d = d_max - d_min + 1

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

cd = lcm(c, d)
cd_min = int(a/cd) if a % c == 0 else int(a/cd) + 1
cd_max = int(b/cd)
delta_cd = cd_max -cd_min + 1

# cとdで割り切れる数
num_cd = delta_c + delta_d - delta_cd
print( b-a+1 - num_cd)

Submission status: Runtime Error

Solution code:
n, l = list(map(int, input().split()))
ts = [l + i - 1 for i in range(1, n + 1)]
print(sum(ts) + min([abs(x) for x in ts]))

Submission status: Runtime Error

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

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

s=B - A + 1 - ((B//C - (A-1)//C)+(B//D - (A-1)//D)-(B//l))
print(s)

Submission status: Runtime Error

Solution code:
import fractions
import AtCoderUtils
Utils = AtCoderUtils.ACUtils()


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

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


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


# def floor(a, b):
#   # return int((a - a%b)/b)
#   return a//b
# def gcd(a, b):
#   while b != 0:
#       a, b = b, a % b
#   return a
# def lcm(a, b):
#   return floor((a * b), gcd(a, b))

firstC = Utils.floor((A-1),C)
firstD = Utils.floor((A-1),D)
firstCD = Utils.floor((A-1),Utils.lcm(C,D))

# if A%lcm(C,D) ==0 and firstCD > 0:
#     firstCD -= 1

endC = Utils.floor(B,C)
endD = Utils.floor(B,D)
endCD = Utils.floor(B,Utils.lcm(C,D))

End = B-endC-firstD + endCD
First = (A-1) - firstC - firstD + firstCD



thereC = endC - firstC
thereD = endD - firstD
thereCD = endCD - firstCD

NoP = thereC+thereD - thereCD

# print(thereC)
# print(thereD)
# print(thereCD)
# print(NoP)
print((B-A+1)-NoP)
# print(End-First)

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)


p = B-(int(B/C) + int(B/D) - int(B/lcm(C,D)))

q = A-1-(int((A-1)/C) + int((A-1)/D) - int((A-1)/lcm(C,D)))

print(p-q)

Submission status: Runtime Error

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

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

s=B - A + 1 - ((B//C - (A-1)//C)+(B//D - (A-1)//D)-(B//l))
print(s)

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
D= b//d-a//d
EX=  lcm(c,d)
EX=b//EX-a//EX
print(b-a+1-(C+D)+EX)

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

if B < C and B < D:
    print(B - A + 1)
    exit()

CD_lcm = C * D // gcd(C, D)

n_cant_divs = []
for target in [C, D, CD_lcm]:
    if A <= target <= B:
        t_cant_div = target - A
        can_div = B // target
        t_cant_div2 = (B - target + 1) - can_div
        n_cant_divs.append(t_cant_div + t_cant_div2)
    elif target < A:
        can_div_w_over = B // target
        correction = (A - 1) // target
        actual_can_div = can_div_w_over - correction
        t_cant_div = (B - A + 1) - actual_can_div
        n_cant_divs.append(t_cant_div)

print(n_cant_divs[0] + n_cant_divs[1] - n_cant_divs[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
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:
# coding: utf-8
a, b, c, d = [int(i) for i in input().split()]
c1, d1 = [d if c < d else c, c if c < d else d]
while d1 > 1:
    e = d1
    d1 = c1 % d1
    c1 = e
e = c * d / e
cnt = (b - a + 1) + int(b / e) - int(a / e) - int(b / c) + int(a / c) - int(b / d) + int(a / d)
print(cnt)

Submission status: Runtime Error

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

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

s=B - A + 1 - ((B//C - (A-1)//C)+(B//D - (A-1)//D)-(B//l))
print(int(s))

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 count_multiple(n):
    return (B // n) - ((A - 1) // n)

def count_not_multiple(n):
    return (B - A + 1) - count_multiple(n)

cnm = count_not_multiple
print(cnm(C) + cnm(D) - cnm(lcm(C, D)))

Submission status: Runtime Error

Solution code:
A,B,C,D = [int(i) for i in input().split()]
import math
l= C * D / math.gcd(C, D)

s=B - A + 1 - ((B//C - (A-1)//C)+(B//D - (A-1)//D)-(B//l))
print(int(s))

Submission status: Runtime Error

Solution code:
A,B,C,D = [int(i) for i in input().split()]
import math
l= C * D / math.gcd(C, D)

s=B - A + 1 - ((B//C - (A-1)//C)+(B//D - (A-1)//D)-(B//l))
print(s)

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

if B < C and B < D:
    print(A - B + 1)
    exit()

CD_lcm = C * D // gcd(C, D)

n_cant_divs = []
for target in [C, D, CD_lcm]:
    if A <= target <= B:
        t_cant_div = target - A
        can_div = B // target
        t_cant_div2 = (B - target + 1) - can_div
        n_cant_divs.append(t_cant_div + t_cant_div2)
    elif target < A:
        can_div_w_over = B // target
        correction = (A - 1) // target
        actual_can_div = can_div_w_over - correction
        t_cant_div = (B - A + 1) - actual_can_div
        n_cant_divs.append(t_cant_div)

print(n_cant_divs[0] + n_cant_divs[1] - n_cant_divs[2])

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = list(map(int,input().split()))
a-=1
cka = int(b/c) - int(a/c) + 1
dka = int(b/d) - int(a/d) + 1
lc = int((c*d)/math.gcd(c, d))
dcka = int(b/lc) - int(a/lc) + 1
print(b-a+1-cka-dka+dcka)

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)

count_B = B - (B // C) - (B // D) + (B // CD)
count_A = A - 1 - ((A - 1) // C) - ((A - 1) // D) + ((A - 1) // CD)

print(count_B - count_A)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

if __name__ == "__main__":
    S = input().split()

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

    CD = lcm(C, D)

    count_B = B - (B // C) - (B // D) + (B // CD)
    count_A = A - 1 - ((A - 1) // C) - ((A - 1) // D) + ((A - 1) // CD)

    print(count_B - count_A)

Submission status: Runtime Error

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

A, B, C, D = map(int, input().split(" "))
ans = 0
Bc = B // C
Bd = B // D
ck = 0

asb = C*D//ck
Bs = B//asb

newb = B - Bc - Bd + Bs

Ac = (A-1) // C
Ad = (A-1) // D
As = (A-1)//asb

newa = (A-1)-Ac-Ad+As

print(int(newb-newa))

Submission status: Runtime Error

Solution code:
import numpy as np
import math

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

a = input()
a, b, c, d = [int(i) for i in a.split(" ")]
dc = (b // c) - ((a-1) // c)
dd = (b // d) - ((a-1)  // d)
dcd = (b // lcm(c, d)) - ((a-1) // lcm(c, d))
print((b - a) + 1 - (dc + dd - dcd))

Submission status: Runtime Error

Solution code:
import math
num = input().split(" ")
a = int(num[0])-1
b = int(num[1])
c = int(num[2])
d = int(num[3])
e = int(c * d / int(math.gcd(c, d)))
bb = b - (b//c) -(b//d) +(b//e) 
aa = a - (a//c) -(a//d) + (a//e)
print(int(bb-aa))

Submission status: Runtime Error

Solution code:
import math

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

A -= 1

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

A_C = A // C
A_D = A // D
A_Z = A // Z

A_num = A - (A_C + A_D - A_Z)

B_C = B // C
B_D = B // D
B_Z = B // Z


B_num = B - (B_C + B_D - B_Z)


print(B_num - A_num)

Submission status: Runtime Error

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

a = input()
a, b, c, d = [int(i) for i in a.split(" ")]
dc = (b // c) - ((a-1) // c)
dd = (b // d) - ((a-1)  // d)
dcd = (b // lcm(c, d)) - (a // lcm(c, d))
print((b - a) + 1 - (dc + dd - dcd))

Submission status: Runtime Error

Solution code:
import math

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

A -= 1

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

A_C = A // C
A_D = A // D
A_Z = A // Z

A_num = A - (A_C + A_D - A_Z)

B_C = B // C
B_D = B // D
B_Z = B // Z


B_num = B - (B_C + B_D - B_Z)


print(B_num - A_num)

Submission status: Runtime Error

Solution code:
import math

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

A, B, C, D = list(map(int, input().split(' ')))
B_C = math.floor(B/C)
#print(B/C,math.floor(B/C))
B_D = math.floor(B/D)
#print(B/D,math.floor(B/D))
A_C = math.ceil(A/C) - 1
#print(A/C,math.ceil(A/C))
A_D = math.ceil(A/D) - 1
#print(A/D,math.ceil(A/D))

C_D = lcm(C,D)
B_C_D = math.floor(B/(C_D))
#print(B/(C_D),math.floor(B/(C_D)))
A_C_D = math.ceil(A/(C_D)) - 1
#print(A/(C_D),math.ceil(A/(C_D)))

print((B - A + 1) - (B_C + B_D - A_C - A_D - (B_C_D - A_C_D)))

Submission status: Runtime Error

Solution code:
import math


# C, Dの最小公倍数を求めておく
def lcm(x, y):
    return (x * y) // math.gcd(x, y)


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

# A以上B以下にあるCとDの倍数を除外した残りの数字を求める
# Cの倍数を求める
start = math.floor((A - 1) / C)
end = math.floor(B / C)

c_multiples_count = end - start

# Dの倍数を求める
start = math.floor((A - 1) / D)
end = math.floor(B / D)

d_multiples_count = end - start

lcm_num = lcm(C, D)

# 公倍数を知る
start = math.floor((A - 1) / lcm_num)
end = math.floor(B / lcm_num)

# 公倍数が含まれる数を求める
lcm_multiples_count = end - start


# A以上B以下にあるCとDの倍数を除外した残りの数字を求める
# 公倍数については重複してカウントされているので足し戻す
ans = B - A - c_multiples_count - d_multiples_count + lcm_multiples_count + 1
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

S = input().split()

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

CD = lcm(C, D)

count_B = B - (B // C) - (B // D) + (B // CD)
count_A = A - 1 - ((A - 1) // C) - ((A - 1) // D) + ((A - 1) // CD)

print(count_B - count_A)

Submission status: Runtime Error

Solution code:
import math
# 最大公約数

a, b, c, d = map(int, input().split())  # 複数数値入力

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

# print(lcm)
# print(b - a + 1)
# print(int(b / c) - int((a - 1) / c))
# print(int(b / d) - int((a - 1) / d))
# print(int(b/lcm)-int((a-1)/lcm))
# print(b - a + 1 - math.floor(b / c) - math.floor(b/d) +
# math.floor((a-1) / c) + math.floor((a-1)/d) + (math.floor(b/lcm) - math.floor((a-1)/lcm)))
print(int(b - a + 1 - b // c - b//d +
          (a-1) // c + (a-1)//d + ((b//lcm) - (a-1)//lcm)))

Submission status: Runtime Error

Solution code:
import math

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

# A以上B以下にあるCとDの倍数を除外した残りの数字を求める
# Cの倍数を求める
start = math.floor((A - 1) / C)
end = math.floor(B / C)

c_multiples_count = end - start

# Dの倍数を求める
start = math.floor((A - 1) / D)
end = math.floor(B / D)

d_multiples_count = end - start


# C, Dの最小公倍数を求めておく
def lcm(x, y):
    return (x * y) // math.gcd(x, y)


lcm_num = lcm(C, D)

# 公倍数を知る
start = math.floor((A - 1) / lcm_num)
end = math.floor(B / lcm_num)

# 公倍数が含まれる数を求める
lcm_multiples_count = end - start


# A以上B以下にあるCとDの倍数を除外した残りの数字を求める
# 公倍数については重複してカウントされているので足し戻す
ans = B - A - c_multiples_count - d_multiples_count + lcm_multiples_count + 1
print(ans)

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

Submission status: Runtime Error

Solution code:
import math
# 最大公約数

a, b, c, d = map(int, input().split())  # 複数数値入力

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

# print(lcm)
# print(b - a + 1)
# print(int(b / c) - int((a - 1) / c))
# print(int(b / d) - int((a - 1) / d))
# print(int(b/lcm)-int((a-1)/lcm))
# print(b - a + 1 - math.floor(b / c) - math.floor(b/d) +
# math.floor((a-1) / c) + math.floor((a-1)/d) + (math.floor(b/lcm) - math.floor((a-1)/lcm)))
print(b - a + 1 - b // c - b//d +
      (a-1) // c + (a-1)//d + ((b//lcm) - (a-1)//lcm))

Submission status: Runtime Error

Solution code:
import math

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

# A以上B以下にあるCとDの倍数を除外した残りの数字を求める
# Cの倍数を求める
start = math.floor((A - 1) / C)
end = math.floor(B / C)

c_multiples_count = end - start

# Dの倍数を求める
start = math.floor((A - 1) / D)
end = math.floor(B / D)

d_multiples_count = end - start


# C, Dの最小公倍数を求めておく
def lcm(x, y):
    return (x * y) // math.gcd(x, y)


LCM = lcm(C, D)

# 公倍数を知る
start = math.floor((A - 1) / LCM)
end = math.floor(B / LCM)

# 公倍数が含まれる数を求める
lcm_multiples_count = end - start


# A以上B以下にあるCとDの倍数を除外した残りの数字を求める
# 公倍数については重複してカウントされているので足し戻す
ans = B - A - c_multiples_count - d_multiples_count + lcm_multiples_count + 1
print(ans)

Submission status: Runtime Error

Solution code:
import math
from fractions import gcd


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

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

def calc(n):
    return n-n//c-n//d+n//(c*d//math.gcd(c, d))


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

Submission status: Runtime Error

Solution code:
# cording: utf-8
import math
num = input().split(" ")
a = int(num[0])-1
b = int(num[1])
c = int(num[2])
d = int(num[3])
e = int(c * d / int(math.gcd(c, d)))
bb = b - (b//c) -(b//d) +(b//e) 
aa = a - (a//c) -(a//d) + (a//e)
print(int(bb-aa))

Submission status: Runtime Error

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

C_ = int(B//C) - int((A-1)//C)
D_ = int(B//D) - int((A-1)//D)

E = int(C * D // int(fractions.gcd(C, D)))
E_ = int(B//E) - int((A_1)//E)

ans = B - A + 1 - C_ - D_ + E_
print(ans)

Submission status: Runtime Error

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

s = input().split(" ");
a = int(s[0]);
b = int(s[1]);
c = int(s[2]);
d = int(s[3]);
num_c = int(b/c) - int((a-1)/c);
num_d = int(b/d) - int((a-1)/d); 
num_cd = int(b/lcm(c, d)) - int((a-1)/lcm);
print(b - a + 1 -(num_c + num_d - num_cd))

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = map(int, input().split(" "))
ans = 0
Bc = B // C
Bd = B // D

ck = math.gcd(C, D)
asb = C*D/ck
Bs = B//asb

newb = B - Bc - Bd + Bs

Ac = (A-1) // C
Ad = (A-1) // D
As = (A-1)//asb

newa = (A-1)-Ac-Ad+As

print(newb-newa)

Submission status: Runtime Error

Solution code:
import math

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

under_a = a -1
cd_gcd = math.gcd(c, d)

b_mul = b - (b//c)-(b//d)+(b//(c*d//cd_gcd))
under_a_mul = under_a - (under_a//c)-(under_a//d)+(under_a//(c*d//cd_gcd))

print(int(b_mul-under_a_mul))