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


if(A%C!=0):
    # 切り上げ
    C_min = math.ceil(A/C)
else:
    C_min = A/C

if(B%C!=0):
    #切り捨て
    C_max = math.floor(B/C)
else:
    C_max = B/C

# 割り切れる個数
C_num = C_max - C_min + 1
#print("C_num",C_num)


if(A%D!=0):
    # 切り上げ
    D_min = math.ceil(A/D)
else:
    D_min = A/D
    
if(B%D!=0):
    #切り捨て
    D_max = math.floor(B/D)
else:
    D_max = B/D
#print("Dmax",D_max)

# 割り切れる個数
D_num = D_max - D_min + 1
#print("D_num",D_num)

lcm = C * D / math.gcd(C, D)
if(A%(lcm)!=0):
    # 切り上げ
    CD_min = math.ceil(A/lcm)
else:
    CD_min = A/lcm

if(B%lcm!=0):
    #切り捨て
    CD_max = math.floor(B/lcm)
else:
    CD_max = B/lcm
    
# 割り切れる個数
CD_num = CD_max - CD_min + 1
#print("CD_num",CD_num)

# AからBまで
num = B - A + 1
#print("num",num)

result = num - (C_num + D_num - CD_num)
print(int(result))

Submission status: Runtime Error

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

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

CD = lcm(C,D)
c_div = 0
d_div = 0
cd_div = 0
ans = 0

if A % C == 0:
    first_C = A
else:
    first_C = A + C -(A%C)
last_C = B -(B%C)
c_div = (last_C - first_C)//C + 1

if A % D == 0:
    first_D = A
else:
    first_D = A + D -(A%D)
    last_D = B - (B%D)
d_div = (last_D - first_D)//D + 1

if A % CD == 0:
    first_CD =A
else:
    first_CD = A + CD -(A%CD)
    last_CD = B -(B%CD)
cd_div = (last_CD - first_CD)//CD + 1

ans = c_div + d_div -cd_div
print(B-A+1-ans)

Submission status: Runtime Error

Solution code:
import math

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
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a, b, c, d = map(int, input().split())
cn = b//c + (-a//c) + 1
dn = b//d + (-a//d) + 1
cd = lcm(c, d)
cdn = b//cd + (-a//cd) + 1
#print(cn, dn, cdn)
print(b-a+1-(cn+dn-cdn))

Submission status: Runtime Error

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

import math

N_C = (B-A) // C
N_D = (B-A) // D
N_CD = (B-A) // (C*D//math.gcd(C, D))

ans = (B-A)-N_C-N_D+N_CD
print(ans)

Submission status: Runtime Error

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

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

# C, D, C*Dで割り切れるものの個数
div_C = B//C - (A//C + (-1 if A%C==0 else 0))  # 40//6 - 10//6 -> 6 - 1 = 5
div_D = B//D - (A//D + (-1 if A%D==0 else 0))  # 40//8 - 10//8 -> 5 - 1 = 4
div_CD = B//(CD) - max(0, (A//(CD) + (-1 if A%(CD)==0 else 0)))
print(B-A+1 - div_C - div_D + div_CD)

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)

allnum =  B -A +1
if A%C==0:
    Csta = A
else:    
    Csta = A + (C-A%C)
if B%C==0:
    Cowa = B
else:    
    Cowa = B -B%C

if A%D==0:
    Dsta = A
else:    
    Dsta = A + (D-A%D)
if B%D==0:
    Dowa = B
else:    
    Dowa = B -B%D     

E = lcm(C, D)
if A%E==0:
    Esta = A
else:    
    Esta = A + (E-A%E)
if B%E==0:
    Eowa = B
else:    
    Eowa = B -B%E     

if A>Csta or B<Csta:
    Cnum = 0
else:
    Cnum = (Cowa-Csta+C)/C

if A>Dsta or B<Dsta:
    Dnum = 0
else:
    Dnum = (Dowa-Dsta+D)/D

if A>Esta or B<Esta:
    Enum = 0
else:
    Enum = (Eowa-Esta+E)/E


num = allnum - Cnum - Dnum + Enum
print(int(num))

Submission status: Runtime Error

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

import math
num_C = math.floor(B/C) - math.ceil(A/C) + 1
num_D = math.floor(B/D) - math.ceil(A/D) + 1

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

lcm_C_D = lcm(C, D)

num_C_D = math.floor(B/lcm_C_D) - math.ceil(A/lcm_C_D) + 1

ans = (B - A +1) - (num_C + num_D - num_C_D)
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

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

lcmCD=lcm(C, D)
ans=B-A+1
ans-=((B//C) - (A//C))
ans-=((B//D) - (A//D))
ans+=((B//lcmCD) - (A//lcmCD))
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())
c_i=a//c
d_i=a//d
cd_i=a//(lcm(c,d))
if not a%c==0:
    c_i+=1
if not a%d==0:
    d_i+=1
if not a%(lcm(c,d))==0:
    cd_i+=1

c_f=b//c
d_f=b//d
cd_f=b//(lcm(c,d))

print(b-a-(c_f+d_f-cd_f-c_i-d_i+cd_i+1)+1)

Submission status: Runtime Error

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


a, b, c, d = (int(i) for i in input().split())
m = lcm(c, d)
#print(m)
print((b-a+1)-(int((b)/c)-int((a-1)/c))-(int((b)/d)-int((a-1)/d))+(int((b)/(m))-int((a-1)/(m))))
#print("b-a", (b-a))
#print(int((b)/c)-int((a-1)/c))
#print((int((b)/d)-int((a-1)/d)))
#print((int((b-1)/m)-int((a-1)/m)))

Submission status: Runtime Error

Solution code:
from math import gcd
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,input().split()))
total1=mota(a,b,c)
#print(total1)
total2=mota(a,b,d)
#print(total2)
h=(c*d)//gcd(c,d)
total3=mota(a,b,h)
#print(h)
#print(total3)
print(b-a+1-(total1+total2-total3))

Submission status: Runtime Error

Solution code:

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

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

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

s = -1
c = C * (A // C + 1)
if c <= B:
    s += (B - c) // C + 1
        
d = D * (A // D + 1)
if d <= B:
    s += (B - d) // D + 1
    
cd_lcm = lcm(C, D)
cdl = cd_lcm * (A // cd_lcm + 1)
if cdl <= B:
    s -= (B - cdl) // cd_lcm + 1

print(B - A - s)

Submission status: Runtime Error

Solution code:
a, b, c, d=map(int, input().split())
count_c&d=0
count_c=0
count_d=0
X=b-a+1
for i in range(a, b+1):
    if i%c==0 && i%d==0:
        count_c&d+=1
    elif i%c==0 && i%d!=0:
        count_c+=1
    elif i%c!=0 && i%d==0:
        count_d+=1

print(X-count_c-count_d+count_c&d)

Submission status: Runtime Error

Solution code:
import math


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


if(A%C!=0):
    # 切り上げ
    C_min = math.ceil(A/C)
else:
    C_min = A/C

if(B%C!=0):
    #切り捨て
    C_max = math.floor(B/C)
else:
    C_max = B/C

# 割り切れる個数
C_num = C_max - C_min + 1
#print("C_num",C_num)


if(A%D!=0):
    # 切り上げ
    D_min = math.ceil(A/D)
else:
    D_min = A/D
    
if(B%D!=0):
    #切り捨て
    D_max = math.floor(B/D)
else:
    D_max = B/D
#print("Dmax",D_max)

# 割り切れる個数
D_num = D_max - D_min + 1
#print("D_num",D_num)

lcm = C * D / math.gcd(C, D)
if(A%(lcm)!=0):
    # 切り上げ
    CD_min = math.ceil(A/lcm)
else:
    CD_min = A/(lcm)

if(B%lcm!=0):
    #切り捨て
    CD_max = math.floor(B/lcm)
else:
    CD_max = B/lcm
    
# 割り切れる個数
CD_num = CD_max - CD_min + 1
#print("CD_num",CD_num)

# AからBまで
num = B - A + 1
#print("num",num)

result = num - (C_num + D_num - CD_num)
print(int(result))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys, math

input = sys.stdin.readline
gcd = math.gcd
A, B, C, D = map(int, input().split(' '))
num = B - A + 1
div_c = B // C - (A - 1) // C
div_d = B // D - (A - 1) // D
lcd = C * D // gcd(C, D)
div_cd = B // lcd - (A - 1) // lcd
print(num - div_c - div_d + div_cd)

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)

CD = lcm(C,D)
c_div = 0
d_div = 0
cd_div = 0

if A % C == 0:
    first_C = A
else:
    first_C = A + C -(A%C)
last_C = B -(B%C)
c_div = (last_C - first_C)//C + 1

if A % D == 0:
    first_D = A
else:
    first_D = A + D -(A%D)
    last_D = B - (B%D)
d_div = (last_D - first_D)//D + 1

if A % CD == 0:
    first_CD =A
else:
    first_CD = A + CD -(A%CD)
    last_CD = B -(B%CD)
cd_div = (last_CD - first_CD)//CD + 1

ans = c_div + d_div -cd_div
print(B-A+1-ans)

Submission status: Runtime Error

Solution code:
import math

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

cnt1 = int((b)/c) - int((a-1)/c)
cnt2 = int((b)/d) - int((a-1)/d)

e = c * d / math.gcd(c, d)
cnt3 = int((b)/e) - int(a/e)

print(b-a+1 - (cnt1+cnt2 - cnt3))

Submission status: Runtime Error

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

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

C_comp = int((B-(B%C))/C) - int(((A-1)-(A-1)%C)/C)
D_comp = int((B-(B%D))/D) - int(((A-1)-(A-1)%D)/D)
CD_comp = int((B-(B%lcm(C,D)))/lcm(C,D)) - int(((A-1)-(A-1)%lcm(C,D))/lcm(C,D))

print((B - A + 1) - (C_comp + D_comp - CD_comp))

Submission status: Runtime Error

Solution code:
import math
temp=list(map(lambda x:int(x),input().split()))
A,B,C,D=temp[0],temp[1],temp[2],temp[3]
public_cd=math.gcd(C,D)

c_n_full=B//C
d_n_full=B//D
cd_n_full=B//((C*D)//public_cd)

c_n_par=(A-1)//C
d_n_par=(A-1)//D
cd_n_par=(A-1)//((C*D)//public_cd)

c_n=c_n_full-c_n_par
d_n=d_n_full-d_n_par
cd_n=cd_n_full-cd_n_par
counter=(B-A+1)-(c_n+d_n)+cd_n

print(counter)

Submission status: Runtime Error

Solution code:
import math

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

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

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:
X0 = a + (c - (a%c))%c
Y0 = a + (d - (a%d))%d

X = {i for i in range(X0,b+1,c)}
Y = {i for i in range(Y0,b+1,d)}
print(b - a  + 1 - len(list(X | Y)))

Submission status: Runtime Error

Solution code:
import math
import fractions
import numpy

np.set_printoptions(suppress=True)


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

G = C * D / fractions.gcd(C,D)

ans = int( B // C - (A-1) // C ) + int(B // D - (A-1) // D) - int(B // G - (A-1) // G)

print (B - A + 1 - 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())

# 変数C の倍数が A, B 区間内に存在しうる数
Ccount = B // C - (A - 1) // C

# 変数D の倍数が A, B 区間内に存在しうる数
Dcount = B // D - (A - 1) // D

# 変数C, D の最小公倍数が A, B 区間内に存在しうる数
CDcross = B // lcm(C, D) - (A - 1) // lcm(C, D)

# Cが存在しうる数と Dが存在しうる数を引き、重複する（＝最小公倍数）数は引きすぎなので戻す
print((B-A+1) - ((Ccount + Dcount - CDcross)))

Submission status: Runtime Error

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

import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
E=lcm(C,D)

if A%C==0:
    nC_initial=A//C
else:
    nC_initial=A//C+1
    
if A%D==0:
    nD_initial=A//D
else:
    nD_initial=A//D+1

    
if A%E==0:
    nE_initial=A//E
else:
    nE_initial=A//E+1
    
nC_final=B//C
nD_final=B//D
nE_final=B//E
if nC_final<nC_initial:
    nC_final=nC_initial
if nD_final<nD_initial:
    nD_final=nD_initial
if nE_final<nE_initial:
    nE_final=nE_initial
#print(ans,nC_initial,nC_final,nD_initial,nD_final, nE_initial,nE_final)
print(ans-(nC_final-nC_initial+1)-(nD_final-nD_initial+1)+(nE_final-nE_initial+1))

Submission status: Runtime Error

Solution code:
import math

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

def f(x, c, d):
    return x-int(x/c)-int(x/d)+int(x/lcm(c,d))

A,B,C,D = list(map(int, input().split()))
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())
nums = b-a+1
# def lastNum_serch(lim,n):
#     i = b
#     while(i >= lim):
#         i -= 1
#         if i % n == 0:
#             return i

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

c_num = b//c - (a-1)//c
d_num = b//d - (a-1)//d
cd_num = b//lcm(c,d) - (a-1)//lcm(c,d)

print(nums-(c_num+d_num-cd_num))

Submission status: Runtime Error

Solution code:
from math import gcd

a, b, c, d = map(int, input().split())
cx = b//c - (a-1)//c
dx = b//d - (a-1)//d
lcm = (c * d) // gcd(c, d)
lcmx = b//lcm - (a-1)//lcm
print(b-a+1-cx-dx+lcmx)

Submission status: Runtime Error

Solution code:
import numpy as np

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

pan = np.arange(a, b, c)
bou = np.arange(a, b, d)
tana = np.arange(a, b, c*d)

print(b-a+1 - len(pan) - len(bou) + len(tana))

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())
ans = set()
if A%C == 0:
    c = (B//C) - (A//C) + 1
else:
    c = (B//C) - (A//C)

if A%D == 0:
    d = (B//D) - (A//D) + 1
else:
    d = (B//D) - (A//D)

CD = lcm(C, D)

if A%CD == 0:
    cd = (B//CD) - (A//CD) + 1
else:
    cd = (B//CD) - (A//CD)

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

Submission status: Runtime Error

Solution code:
import math

parents = list(map(int,input().split(' ')))
All = parents[1] - parents[0]
min_2 = (parents[2]*parents[3]) // math.gcd(parents[2], parents[3])
print(All-All//parents[2]-All//parents[3]+All//min_2)

Submission status: Runtime Error

Solution code:
import numpy as np
a = input()
a, b, c, d = [int(i) for i in a.split(" ")]
num = np.arange(a, b)
print((num % (c * d) == 0).sum())

Submission status: Runtime Error

Solution code:
import math


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


abcd = input().split(" ")
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])
cd = lcm(c, d)

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

Submission status: Runtime Error

Solution code:
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654

import math
import sys
import itertools
import queue

mod = 1000000007

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

if __name__ == "__main__":
    A, B, C, D = map(int, sys.stdin.readline().split())
    A = A - 1
    c_div = math.floor(B / C)
    #nc_div = (B - c_div)
    d_div = math.floor(B / D)
    #nd_div = (B - d_div)
    cd_div = math.floor(B / lcm(C, D))
    #ncd_div = (B - cd_div)
    #print(nc_div)
    #print(nd_div)
    #print(ncd_div)


    not_div1 = B - (c_div + d_div -cd_div)

    c_div = math.floor(A / C)
    nc_div = (A - c_div)
    d_div = math.floor(A / D)
    nd_div = (A - d_div)
    cd_div = math.floor(A / lcm(C, D))
    ncd_div = (A - cd_div)

    not_div2 = A - (c_div + d_div -cd_div)
    #not_div2 = nc_div + nd_div - ncd_div

    #print(not_div1)
    #print(not_div2)

    #print(not_div2)

    print(not_div1 - not_div2)

Submission status: Runtime Error

Solution code:
import math
import sys

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


A,B,C,D = map(int,input().split())
if C == 1 or D == 1:
    print(0)
    sys.exit(0)

E = lcm(C,D)
c = (A-1)//C + 1 if C!=1 else A
d = (A-1)//D + 1 if D!=1 else A
e = (A-1)//E + 1 if E!=1 else A
cde = [[c,C], [d,D], [e,E]]
cnt_cde = []
for x,y in cde:
    if x*y < B:
        cnt_cde.append((B-x*y)//y+1)
    elif x*y == B:
        cnt_cde.append(1)
    else :
        cnt_cde.append(0)
answer = B-A+1-(cnt_cde[0]+cnt_cde[1]-cnt_cde[2])
print(answer)

Submission status: Runtime Error

Solution code:
import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)
  
def main(str):
    input = str.split()
    a = int(input[0])
    b = int(input[1])
    c = int(input[2])
    d = int(input[3])
    cd = lcm(c, d)

    return (
        b
        - a
        + 1
        - b // c
        + (a - 1) // c
        - b // d
        + (a - 1) // d
        + b // cd
        - (a - 1) // cd
    )


if __name__ == "__main__":
    str = input()
    print(main(str))

Submission status: Runtime Error

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

num_div_C = math.floor(B / C) - math.floor(A / C)
num_div_D = math.floor(B / D) - math.floor(A / D)
lcm = C * D // math.gcd(C, D)
num_div_CD = math.floor(B / lcm) - math.floor(A / lcm)

print(B - A + 1 - (num_div_C + num_div_D - num_div_CD))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = map(int, input().split())
x = abs(A-B)//C + 1
y = abs(A-B)//D + 1
if abs(A-B)//((C*D)//math.gcd(C,D)) == 0:
    z = 0
else:
    z = abs(A-B)//((C*D)//math.gcd(C,D)) + 1
print(B-A+1-x-y+z)

Submission status: Runtime Error

Solution code:
import math

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

c1 = int((B - B%C)/C) - int(((A-1) - (A-1)%C)/C)
d1 = int((B - B%D)/D) - int(((A-1) - (A-1)%D)/D)

CD = int((C * D - C * D % math.gcd(C, D)) / math.gcd(C, D))
cd1 = int((B - B%CD)/CD) - int(((A-1) - (A-1)%CD)/CD)

ans = B - (A-1) - (c1 + d1 - cd1)
print(ans)

Submission status: Runtime Error

Solution code:
import math
p=input().rstrip().split(' ')
a=int(p[0])
b=int(p[1])
c=int(p[2])
d=int(p[3])
e=(b//c)-(a//c)
if (a%c==0):
    e+=1;
f=(b//d) - (a//d);
if (a%d==0):
    f+=1;
g=b-a+1
h=math.gcd(c,d)
i=(c*d)//h
if i==0:
    j=0;
else:
    j=b//i
k=e+f-j
l=g-k
print(l)

Submission status: Runtime Error

Solution code:
import math

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

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

s = -1
c = C * (A // C + 1)
if c <= B:
    s += (B - c) // C + 1
        
d = D * (A // D + 1)
if d <= B:
    s += (B - d) // D + 1
    
cd_lcm = lcm(C, D)
cdl = cd_lcm * (A // cd_lcm + 1)
if cdl <= B:
    s -= (B - cdl) // cd_lcm + 1

print(B - A - s)

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])
x = b - (b//c) -(b//d) +(b//(c*d//math.gcd(c, d))) -(a -(a//c) -(a//d) + a//(c*d//math.gcd(c, d)))
print(x)

Submission status: Runtime Error

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

num_div_C = math.floor(B / C) - math.floor(A / C)
num_div_D = math.floor(B / D) - math.floor(A / D)
lcm = C * D // math.gcd(C, D)
num_div_CD = math.floor(B / lcm) - math.floor(A / lcm)

print(B - A + 1 - (num_div_C + num_div_D - num_div_CD))

Submission status: Runtime Error

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

import math

interval = B-A+1

n1 = math.ceil(A/C)
n2 = math.ceil(A/D)
m1 = math.ceil(B/C)
m2 = math.ceil(B/D)

arr1 = []
arr2 = []

if B%C==0:
    for i in range(n1, m1+1):
        arr1.append(i*C)
else:
    for i in range(n1, m1):
        arr1.append(i*C)
        
if B%D==0:
    for j in range(n2, m2+1):
        arr2.append(j*D)
else:
    for j in range(n2, m2):
        arr2.append(j*D)
    
cnt_c = len(arr1)
cnt_d = len(arr2)
cnt_cd = sum([arr[i]%C==0 for i in range(len(arr))])
cnt = cnt_c+cnt_d-cnt_cd

print(interval-cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = map(int, input().split())
NBC = B//C
NBD = B//D
CD_lcm = (C*D)//math.gcd(C,D)   #CとDの最小公倍数
NBCD = B//CD_lcm #CとD共通で割り切れる数
B_0 = (NBC+NBD)-NBCD  #Bの答え
ans_B = B-B_0
NAC = (A)//C
NAD = (A)//D
NACD = (A)//CD_lcm  
A_0 = (NAC+NAD)-NACD #Aの答え
ans_A = A-A_0
if A%C==0 or A%D==0:
    ans = ans_B-ans_A
else:
    ans = ans_B-ans_A+1
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
a,b,c,d= map(int,input().split())
count = 0
kou = (c*d) // math.gcd(c,d)
#print(kou)
if a % kou == 0:
    hajime = a
else :
    hajime = (kou - a % kou) + a
owari = b - (b % kou)
if a % c == 0:
    chajime = a
else :
    chajime = (c - a % c) + a
cowari = b - (b % c)
if a % d == 0:
    dhajime = a
else :
    dhajime = (d - a % d) + a
dowari = b - (b % d)


kousuu = ((cowari - chajime) // c + 1) + ((dowari - dhajime) // d + 1) - ((owari - hajime) // kou + 1)
sa = b - a + 1
print(sa - (kousuu))
#print(hajime,owari,chajime,cowari,dhajime,dowari,)

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()))
    
CD = lcm(C, D) 

n_C = int(np.floor(B/C) - np.floor((A-1)/C))
n_D = int(np.floor(B/D) - np.floor((A-1)/D))

n_CD = int(np.floor(B/CD) - np.floor((A-1)/CD))

print('{}'.format(B-A+1-(n_C+n_D-n_CD)))

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)

cnt = 0

# A
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
def lcm(x,y):
    return x*y//math.gcd(x,y)

def ABC(x,y,z):
    return z-(z//x+z//y-z//lcm(x,y))

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

Submission status: Runtime Error

Solution code:

import math

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

#print(CD)

C_count = B//C - (A-1)//C 
D_count = B//D - (A-1)//D
CD_count = B//CD - (A-1)//CD 



#print(C_count, D_count, CD_count)

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

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())
count = 0
lcm = lcm(c,d)
ans1 = (b // c - a // c + b // d - a // d - b // lcm + a // lcm)
print(b - a - ans1 + 1)

Submission status: Runtime Error

Solution code:
import math

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

for i in range(A, B+1):
    if i % C == 0:
        cntC = 1 + int((B-i)/C)
        break

for i in range(A, B+1):
    if i % D == 0:
        cntD = 1 + int((B-i)/ D)
        break

for i in range(A, B+1):
    if i % CD == 0:
        cntCD = 1 + int((B-i)/CD)
        break

# print(cntC, cntD, cntCD, CD)
calc = (B-A+1) - (cntC + cntD - cntCD)

print(calc)

Submission status: Runtime Error

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

if A%C==0:
    x=B//C-A//C+1
else:
    x=B//C-A//C
if A%D==0:
    y=B//D-A//D+1
else:
    y=B//D-A//D
E=C*D/math.gcd(C,D)
if A%E==0:
    z=B//E-A//E+1
else:
    z=B//E-A//E
print(round(B-A+1-(x+y-z)))

Submission status: Runtime Error

Solution code:
import math

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

a, b, c, d = map(int, input().split())
count = 0
if a%c==0:
    lower1 = a//c
else:
    lower1 = a//c + 1
if a%d==0:
    lower2 = a//d
else:
    lower2 = a//d + 1
if a%lcm(c,d)==0:
    lower3 = a//lcm(c,d)
else:
    lower3 = a//lcm(c,d) + 1
higher1 = b//c
higher2 = b//d
higher3 = b//lcm(c,d)

count = higher1 - lower1 + 1 + higher2 - lower2 + 1 - higher3 - lower3 + 1

print(b - a + 1 - count)

Submission status: Runtime Error

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

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

print(s - (dev(c) + dev(d) - dev(c * d // math.gcd(c, d))))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

# Cで割り切れる数
div_c_min = math.ceil(A/C)
div_c_max = math.floor(B/C)
div_c_num = div_c_max - div_c_min + 1
#print(div_c_min, div_c_max)
#print(div_c_num)

# Dで割り切れる数
div_d_min = math.ceil(A/D)
div_d_max = math.floor(B/D)
div_d_num = div_d_max - div_d_min + 1
#print(div_d_min, div_d_max)
#print(div_d_num)

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

# CとDの公倍数で割り切れる数
div_cd_min = math.ceil(A / lcm(C, D))
div_cd_max = math.floor(B / lcm(C, D))
div_cd_num = div_cd_max - div_cd_min + 1
#print(div_cd_min, div_cd_max)
#print(div_cd_num)

numAtoB = B - A + 1
print(numAtoB - (div_c_num + div_d_num - div_cd_num))

Submission status: Runtime Error

Solution code:
import math

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


A,B,C,D = map(int,input().split())
E = lcm(C,D)
c = (A-1)//C + 1 if C!=1 else A
d = (A-1)//D + 1 if D!=1 else A
e = (A-1)//E + 1 if E!=1 else A
cde = [[c,C], [d,D], [e,E]]
cnt_cde = []
for x,y in cde:
    if x*y < B:
        cnt_cde.append((B-x*y)//y+1)
    elif x*y == B:
        cnt_cde.append(1)
    else :
        cnt_cde.append(0)
answer = B-A+1-(cnt_cde[0]+cnt_cde[1]-cnt_cde[2])
print(answer)

Submission status: Runtime Error

Solution code:
def C():
    import math
    
    def counter (target):
        flg = False
        for i in range(A, B + 1):
            if i % target == 0:
                leg = B - i
                count = (leg // target) + 1
                flg = True
                break
        if flg == False:
            count = 0
        return count
    A, B, C, D = map(int, input().split())
    lcm = (C * D) // math.gcd(C, D)

    print(B - A + 1 - (counter(C) + counter(D) - counter(lcm)))



C()

Submission status: Runtime Error

Solution code:
import math

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

bc = B // C
bd = B // D
be = B // int((C*D/math.gcd(C, D)))
BB = B - bc - bd + be

ac = (A-1) // C
ad = (A-1) // D
ae = (A-1) // int(C*D/math.gcd(C, D))
AA = (A-1) - ac - ad + ae

print(BB-AA)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

lcm = C*D/math.gcd(C,D)
b_s = int(B/C) + int(B/D) - int(B/lcm)
a_s = int((A-1)/C) + int((A-1)/D) - int((A-1)/lcm)
print(B-A+1-(b_s - a_s))

Submission status: Runtime Error

Solution code:
import math

A, B, C, D = map(int, input().split(' '))
num = B - A + 1
div_c = B // C - (A - 1) // C
div_d = B // D - (A - 1) // D
lcd = C * D // math.gcd(C, D)
div_cd = B // lcd - (A - 1) // lcd
print(num - div_c - div_d + div_cd)

Submission status: Runtime Error

Solution code:
import math

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

c = int((B - B%C)/C) - int(((A-1) - (A-1)%C)/C)
d = int((B - B%D)/D) - int(((A-1) - (A-1)%D)/D)

CD = int((C * D - C * D % math.gcd(C, D)) / math.gcd(C, D))
cd = int((B - B%CD)/CD) - int(((A-1) - (A-1)%CD)/CD)

ans = B - (A-1) - (c + d - cd)
print(ans)

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 = int((c*d)/math.gcd(c, d))
# print("lcm",lcm)
dcka = math.floor(b/(lcm)) - math.ceil(a/(lcm)) + 1
# print(cka,dka,dcka)
print(b-a+1-cka-dka+dcka)

Submission status: Runtime Error

Solution code:
import math
def lcm(a,b):
    return int(a * b / math.gcd(a, b))
a, b, c, d = map(int, input().split())
b1 = b // c
a1 = a // c
b2 = b // d
a2 = a // d
a3 = a // lcm(c,d)
b3 = b // lcm(c,d)
a_ans = a1 + a2 - a3
b_ans = b1 + b2 - b3
diff = b - a
ans = diff - (b_ans - a_ans)
if (lcm(a,b) != a*b):
    ans += 1
print(ans)

Submission status: Runtime Error

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

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

cd = lcm(c, d)

ca = (a // c)
cb = (b // c)
tmp_c = cb - ca

da = (a // d)
db = (b // d)
tmp_d = db - da

cda = (a // cd)
cdb = (b // cd)
tmp_cd = cdb - cda
ans = b - a - (tmp_c + tmp_d - tmp_cd) + 1

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[129]:


import math


# In[124]:


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


# In[130]:


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


# In[131]:


c_part_a = int((A - 1) / C)
d_part_a = int((A - 1) / D)
cd_part_a = int((A - 1) / lcm)

c_part_b = int(B / C)
d_part_b = int(B / D)
cd_part_b = int(B / lcm)


# In[132]:


ans1 = (A-1) - (c_part_a + d_part_a - cd_part_a)
ans2 = B - (c_part_b + d_part_b - cd_part_b)


# In[133]:


print(ans2 - ans1)


# In[ ]:

Submission status: Runtime Error

Solution code:
import math
def lcm(a,b):
    return a*b//math.gcd(a,b)
def countD(A, B, M): 
    if (A % M == 0): 
        return ((B // M) - (A // M)) + 1
    return ((B // M) - (A // M)) 
  
a,b,c,d=map(int,input().split())
n=b-a+1

ans=int(countD(a,b,c)+countD(a,b,d)-countD(a,b,lcm(c,d)))

print(n-ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

NumC = math.floor(B / C) - math.ceil(A /C) + 1

NumD = math.floor(B / D) - math.ceil(A /D) + 1

CD = (C * D) // math.gcd(C, D)
NumCD = math.floor(B / CD) - math.ceil(A / CD) + 1

print(Num - NumC - NumD + NumCD)

Submission status: Runtime Error

Solution code:
from math import gcd

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

a, b, c, d = map(int, input().split())
count = 0
if a%c==0:
    lower1 = a//c
else:
    lower1 = a//c + 1
if a%d==0:
    lower2 = a//d
else:
    lower2 = a//d + 1
if a%lcm(c,d)==0:
    lower3 = a//lcm(c,d)
else:
    lower3 = a//lcm(c,d) + 1
higher1 = b//c
higher2 = b//d
higher3 = b//lcm(c,d)

count = higher1 - lower1 + 1 + higher2 - lower2 + 1 - higher3 - lower3 + 1

print(b - a + 1 - count)

Submission status: Runtime Error

Solution code:
from math import gcd

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

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

S1 = A - ( A//C + A//D - A//lcm(C, D) ) - (1 if A%C and A%D else 0)
S2 = B - ( B//C + B//D - B//lcm(C, D) )

print(S2 - S1)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=list(map(int,input().split(" ")))
g=math.gcd(c,d)
cd=c*d
Ncd=int(b/(cd/g))-int(a/(cd/g))
Nc=int(b/c)-int(a/c)
Nd=int(b/d)-int(a/d)
print(b-a-(Nc+Nd-Ncd))