Problem:


Score : 300 points

Problem Statement

You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Constraints

1\leq A\leq B\leq 10^{18}

1\leq C,D\leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Sample Input 1

4 9 2 3

Sample Output 1

2

5 and 7 satisfy the condition.

Sample Input 2

10 40 6 8

Sample Output 2

23

Sample Input 3

314159265358979323 846264338327950288 419716939 937510582

Sample Output 3

532105071133627368



Sample input:
4 9 2 3


Sample output:
2

Submission status: Runtime Error

Solution code:
import math

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

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

Submission status: Runtime Error

Solution code:
import math

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

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

# 0 => A-1 で割りきれる
cnt_c = (A-1) // C
cnt_d = (A-1) // D

cnt_cd = (A-1) // lcm(C, D)

cnt_a = cnt_c + cnt_d - cnt_cd

# 0 => Bで割りきれる
cnt_c2 = B // C
cnt_d2 = B // D
cnt_cd2 = B // lcm(C, D)

cnt_b = cnt_c2 + cnt_d2 - cnt_cd2

cnt_ab = cnt_b - cnt_a

cnt_n = B - A + 1

print(cnt_n - cnt_ab)

Submission status: Runtime Error

Solution code:
import math

A = int(input())
B = int(input())
C = int(input())
D = int(input())

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

nC = int((A - 1) // C)
nD = int((A - 1) // D)
mC = int(B // C)
mD = int(B // D)

nM = int((A - 1) // multi)
mM = int(B // multi)

wC = mC - nC
wD = mD - nD
wM = mM - nM
wCD = wC + wD - wM

nGcd = int((A - 1) // multiGcd)
mGcd = int(B // multiGcd)
wGcD = mGcd - nGcd

ans = B - (A - 1) - wCD
if multiGcd != multi:
    ans += wGcD
print(ans)

Submission status: Runtime Error

Solution code:
A,B,C,D = map(int,input().split())
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(a, b):
    gc = gcd(a, b)
    if gc != 0:
        return a * b // gcd (a, b)
    else:
        return a * b
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

a, b, c, d = map(int,input().split())
cn_l, cn_r, cn_d = 0,0,0
l_list = []
r_list = []
if a%c == 0:
    start_l = a//c
else:
    start_l = a//c+1
# print('left')
cn_l = b//c+1 - start_l
# for i in range(start_l, b//c+1):
#     l_list.append(c*i)
#     cn_l += 1
if a%d == 0:
    start_r = a//d
else:
    start_r = a//d+1
# print('right')
cn_r = b//d+1 - start_r
# for i in range(start_r, b//d+1):
#     r_list.append(d*i)
#     cn_r += 1
# print(cn_l, cn_r)
# for val in l_list:
#     if val in r_list:
#         cn_d +=1
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
lcm = lcm(c,d)
if a%lcm == 0:
    start_d = a//lcm
else:
    start_d = a//lcm+1
cn_d = b//lcm+1 - start_d
n = b-a+1
print(n-(cn_l+cn_r-cn_d))

Submission status: Runtime Error

Solution code:
import math

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

cntC = int(B / C) - int(A / C)
cntD = int(B / D) - int(A / D)
cntCD = int(B / CD) - int(A / CD)

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

print(calc)

Submission status: Runtime Error

Solution code:
A = int(input())
B = int(input())
C = int(input())
D = int(input())

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

nC = int((A - 1) // C)
nD = int((A - 1) // D)
mC = int(B // C)
mD = int(B // D)

nM = int((A - 1) // multi)
mM = int(B // multi)

wC = mC - nC
wD = mD - nD
wM = mM - nM
wCD = wC + wD - wM

nGcd = int((A - 1) // multiGcd)
mGcd = int(B // multiGcd)
wGcD = mGcd - nGcd

ans = B - (A - 1) - wCD
if multiGcd != multi:
    ans += wGcD
print(ans)

Submission status: Runtime Error

Solution code:
import math

a,b,c,d=map(int, input().split())
tisai = c*d/math.gcd(c,d)
n=[c,d]
count=0
for k in range(2):
    count+= ((b+1)//n[k])-(a//n[k])
    # print(count)
count-= ((b+1)//tisai)-(a//tisai)
# print(count)
print(int((b-a+1)-count))

Submission status: Runtime Error

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

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

#print(X,Y)

#count = (B - A) // X * Y 
#print(count)


N = A % X 
N_S = N-1
UA = Y - (N_S // C + N_S // D)

#print(UA)
M = B % X
UB = M // C + M // D
if M == 0:
    UB = 0
#print(UB)


SA =  A + ( X - N )
SB =  B - M 
#print(SA,SB)
count = (SA - SB) // X * Y 

add = count + UA + UB
    
Z = B - A - add + 1
print(Z)

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

print(((ns%C!=0)*(ns%D!=0)).sum())

Submission status: Runtime Error

Solution code:
from math import gcd

a, b, c, d = [int(i) for i in input().split()]
# 4 types of numbers, not divisible by c, not divisible by d
# divisible by c only
# divisible by d only
# divisible by both
# set(not c and not d) = total - divisible by c or d
# = total - (total c + total d - intersection of c and d)

def factorcount(x, sub_x):
    return x // sub_x

def twofactorcounts(x, sub_x, sub_y):
    return factorcount(x, sub_x) + factorcount(x, sub_y) - factorcount(x, sub_x * sub_y //gcd(sub_x, sub_y))

def complementcount(t, c, d):
    return t - twofactorcounts(t, c, d)

print(complementcount(b, c, d) - complementcount(a-1, 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)
s = b-a+1

cd = c*d // math.gcd(c,d)
a_ = ((a-1)//c + (a-1)//d) - ((a-1)//cd)
b_ = (b//c + b//d) - (b//cd)
s_ = b_- a_
print(s-s_)

Submission status: Runtime Error

Solution code:
import math

def num(a, b, x):
    return math.ceil(b/x) - math.floor(a/x) + 1

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

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

num_c = num(a, b, c)
num_d = num(a, b, d)
num_lcm = num(a, b, lcm)
n = num_c + num_d - num_lcm
result = b - a + 1 - n

print(result)

Submission status: Runtime Error

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

import math

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

com = lcm(c,d)

total = b - a + 1
fir = b//c - (a-1)//c
sec = b//d - (a-1)//d
rem = b//com - (a-1)//com

result = total - (fir + sec -rem)
  
print(result)

Submission status: Runtime Error

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


an1 = math.floor(b/c)
an2 = math.floor((a-1)/c)
an3 = math.floor(b/d)
an4 = math.floor((a-1)/d)

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

an5 = math.floor(b/gcd)
an6 = math.floor((a-1)/gcd)
an = an1-an2 + an3-an4 -(an5-an6)
print((b-a+1)-an)

Submission status: Runtime Error

Solution code:
def baisu(x,a):
    if x%a ==0:
        return int(x//a)
    else:
        x -=1
        return baisu(x,a)

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

to_a = a - baisu(a,c) - baisu(a,d) + baisu(a,c*d)
to_b = b - baisu(b,c) - baisu(b,d) + baisu(b,c*d)

if a%c == 0 or a%d == 0:
    print(int(to_b - to_a))
else:
    print(int(to_b-to_a+1))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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)

cc=math.floor(b/c)-math.ceil(a/c)+1
dd=math.floor(b/d)-math.ceil(a/d)+1
cd=math.floor(b/(lcm(c, d)))-math.ceil(a/(lcm(c, d)))+1

print(b-a+1-(cc+dd-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
from functools import reduce
from fractions import gcd

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

mod = 1000000007

"""
def gcd(a,b):
    """Compute the greatest common divisor of a and b"""
    while b > 0:
        a, b = b, a % b
    return a

def lcm(a, b):
    """Compute the lowest common multiple of a and b"""
    return a * b // gcd(a, b)
"""

if __name__ == "__main__":
    A, B, C, D = map(int, sys.stdin.readline().split())
    A = A - 1
    c_div = int(B // C)
    d_div = int(B // D)
    cd_div = int(B // lcm(C, D))

    not_div1 = B - (c_div + d_div -cd_div)

    c_div = int(A // C)
    d_div = int(A // D)
    cd_div = int(A // lcm(C, D))

    not_div2 = A - (c_div + d_div -cd_div)

    print(not_div1 - not_div2)

Submission status: Runtime Error

Solution code:
import math

A, B, C, D = map(int, input().split(" "))
r = B - A + 1
n_C = round(r / C)
n_D = round(r / D)
n_CD = round(r / ((C * D) // math.gcd(C, D)))
print(r - (n_C + n_D - n_CD))

Submission status: Runtime Error

Solution code:
A, B, C, D = map(int,input().split())
C_min = 0
D_min = 0
for i in range(A,B+1):
  if i % C == 0:
    C_min = i
  if i % D == 0:
    D_min = i
  if i % C == 0 and i % D == 0:
    CD_min = i
  if C_min and D_min and CD_min:
    break
C_cou = (B - C_min) // C
D_cou = (B - D_min) // D
CD_cou = (B - CD_min) // (C*D)
ans = B - A - C_cou - D_cou + CD_cou
print(ans)

Submission status: Runtime Error

Solution code:
import math

def lcm(x, y):
    div, _ = divmod(x * y, math.gcd(x, y))
    return div


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

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

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

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

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

Submission status: Runtime Error

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

if a % c == 0:
    c_start = int(a/c)
else:
    c_start = int(a/c)+1

if a % d == 0:
    d_start = int(a/d)
else:
    d_start = int(a/d)+1

c_end = int(b/c)
d_end = int(b/d)

c_list=[0]*(c_end-c_start+1)
d_list=[0]*(d_end-d_start+1)

for ii in range(len(c_list)):
    jj = c_start + ii
    c_list[ii] = jj * c

for ii in range(len(d_list)):
    jj = d_start + ii
    d_list[ii] = jj * d

union = set(c_list) | set(d_list)

print(b - a + 1 - len(union))

Submission status: Runtime Error

Solution code:
import math


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


if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    warikireru_c = math.floor(b / c) - math.ceil(a / c) + 1
    warikireru_d = math.floor(b / d) - math.ceil(a / d) + 1
    lcm_1 = lcm(c, d)
    warikireru_lcm = math.floor(b / lcm_1) - math.ceil(a / lcm_1) + 1
    num = b - a + 1
    print(num - (warikireru_c + warikireru_d - warikireru_lcm))

Submission status: Runtime Error

Solution code:
import math

a,b,c,d = map(int,input().split(" "))
dif = 0
plus = 0
lcm = c * d // math.gcd(c,d)
e = b + 1 - a

dif += b // c - (a - 1) // c
dif += b // d - (a - 1) // d
if c != d:
    plus += b // lcm - (a -1) // lcm

print(e - dif + plus)

Submission status: Runtime Error

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

cmlist = np.nonzero(ndcage % C)[0]
dmlist = np.nonzero(ndcage % D)[0]

count=0
for i in cmlist:
    if i in dmlist:
        count+=1
print(count)

Submission status: Runtime Error

Solution code:
import math

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

nC = int(math.floor((A - 1) / C))
nD = int(math.floor((A - 1) / D))
mC = int(math.floor(B / C))
mD = int(math.floor(B / D))

nM = int(math.floor((A - 1) / multi))
mM = int(math.floor(B / multi))

wC = mC - nC
wD = mD - nD
wM = mM - nM
wCD = wC + wD - wM

nGcd = int(math.floor((A - 1) / multiGcd))
mGcd = int(math.floor(B / multiGcd))
wGcD = mGcd - nGcd

ans = B - (A - 1) - wCD
if multiGcd != multi:
    ans += wGcD
print(ans)

Submission status: Runtime Error

Solution code:
import math

A,B,C,D = map(int,input().split(" "))
min_C = B//C-(A-1)//C
min_D = B//D-(A-1)//D
lcm = C*D//math.gcd(C,D)
min_lcm = B//lcm-(A-1)//lcm
print(B-A-min_C-min_D+min_lcm+1)

Submission status: Runtime Error

Solution code:
import math
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/math.gcd(C,D))!=0:
        CD_min=A-A%(C*D/math.gcd(C,D))+(C*D/math.gcd(C,D))
    else:
        CD_min=A
    CD_max=B-B%(C*D/math.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/math.gcd(C,D))+1
    sum= B-A+1-(C_sum+D_sum-CD_sum)
    return sum

sum=main()
print(sum)

Submission status: Runtime Error

Solution code:
import math

A, B, C, D = map(int, input().split(" "))
r = B - A + 1
n_C = round(r / C)
n_D = round(r / D)
n_CD = round(r / ((C * D) // math.gcd(C, D)))
print(r - (n_C + n_D - n_CD))

Submission status: Runtime Error

Solution code:
import numpy as np
import math


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


if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    warikireru_c = math.floor(b / c) - math.ceil(a / c) + 1
    warikireru_d = math.floor(b / d) - math.ceil(a / d) + 1
    lcm = lcm(c, d)
    warikireru_lcm = math.floor(b / lcm) - math.ceil(a / lcm) + 1
    num = b - a + 1
    print(num - (warikireru_c + warikireru_d - warikireru_lcm))

Submission status: Runtime Error

Solution code:
import math

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

e=b-a
f=a-1

g = int(b/c) + int(b/d) - int(b/((c * d) // math.gcd(c, d)))
h = int(f/c) + int(f/d) - int(f/((c * d) // math.gcd(c, d)))
print(e+1 - g + h)

Submission status: Runtime Error

Solution code:
import math

A,B,C,D = map(int,input().split())
lcm = C*D/math.gcd(C,D)
def c_in_a2b(c):
    return (math.ceil(B//c) - math.floor(A//c) + 1)
print(int((B-A+1)- c_in_a2b(C)-c_in_a2b(D)+c_in_a2b(lcm)))

Submission status: Runtime Error

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

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

ac = (a-1) // c
ad = (a-1) // d
ae = (a-1) // e
bc = b // c
bd = b // d
be = b // e
print((b-a+1) - ((bc + bd - be) - (ac + ad - ae)))

Submission status: Runtime Error

Solution code:
import math

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

c_st = (A-1) // C
c_end = B // C
c_num = c_end - c_st

d_st = (A-1) // D
d_end = B // D
d_num = d_end - d_st

E = (C * D) // math.gcd(C, D)
e_st = (A-1) // E
e_end = B // E
e_num = e_end - e_st

ans = B - A - c_num - d_num + e_num + 1
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

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

Cs = A - (A%C)
Ds = A - (A%D)
CDs = A - (A%CD)

count1 = 0
count2 = 0
count3 = 0

while(True):
    if A <= Cs <= B:
        count1 += 1
    elif Cs > B:
        break
    Cs += C

while(True):
    if A <= Ds <= B:
        count2 += 1
    elif Ds > B:
        break
    Ds += D

while(True):
    if A <= CDs <= B:
        count3 += 1
    elif CDs > B:
        break
    CDs += CD

print(B - A + 1 - ((count1 + count2) - count3))

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
ans1=b//c-(a-1)//c
ans2=b//d-(a-1)//d

import math
e=(c*d)//math.gcd(c,d)
ans3=b//e-(a-1)//e

ans=b-a+1-ans1-ans2+ans3

print(ans)

Submission status: Runtime Error

Solution code:
A, B, C, D = map(int, input().split())
AC = (A - 1) // C
AD = (A - 1) // D
BC = B // C
BD = B // D
BCD = B // lcm(C, D)
ACD = (A - 1) // lcm(C, D)
tmp = (BC + BD) - (AC + AD) - (BCD - ACD)
ans = (B - A + 1) - tmp
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

def gcd(a,b):
    while b > 0:
        a, b = b, a % b
    return a
    
def lcm(a, b):
    return a * b / gcd(a, b)
    
a,b,c,d=input().split()
print((b-a+1-(((b-b%c)-(a+(c-a%c)%c))/c+1))+(b-a+1-(((b-b%d)-(a+(d-a%d)%d))/d+1))-(b-a+1-(((b-(b%(lcm(c,d))))-(a+((lcm(c,d))-a%(lcm(c,d)))%(lcm(c,d))))/(lcm(c,d))+1)))

Submission status: Runtime Error

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

if A%C == 0:
    cnt_c = A//C - 1
else:
    cnt_c = A//C

if A%D == 0:
    cnt_d = A//D - 1
else:
    cnt_d = A//D

if A%(C*D) == 0:
    cnt_cd = A//(C*D) - 1
else:
    cnt_cd = A//(C*D)

num = (B//C)+(B//D)-(B//(C*D)) - (cnt_c + cnt_d - cnt_cd)
print(B-A+1-num)

Submission status: Runtime Error

Solution code:
import math

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

e=b-a
f=a-1

b_ = int(b/c) + int(b/d) - int(b/((c * d) // math.gcd(c, d)))
a_ = int(f/c) + int(f/d) - int(f/((c * d) // math.gcd(c, d)))
print(e+1 - b_ + a_)

Submission status: Runtime Error

Solution code:
import sys
from io import StringIO
import unittest
import math

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

def resolve():
    A, B, C, D = map(int, input().split())
    size = B - A + 1
    C_warikire = math.ceil(size / C)
    D_warikire = math.ceil(size / D)
    C_and_D_warikire = math.ceil(size / (lcm(C, D)))
    print(size - C_warikire - D_warikire + C_and_D_warikire)
    
resolve()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def baisu(x,a):
    if x%a ==0:
        return int(x//a)
    else:
        x -=1
        return baisu(x,a)

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

to_a = a - baisu(a,c) - baisu(a,d) + baisu(a,c*d)
to_b = b - baisu(b,c) - baisu(b,d) + baisu(b,c*d)

print(int(to_b -to_a))

Submission status: Runtime Error

Solution code:
import math

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

nC = int(math.floor((A - 1) / C))
nD = int(math.floor((A - 1) / D))
mC = int(math.floor(B / C))
mD = int(math.floor(B / D))

nM = int(math.floor((A - 1) / multi))
mM = int(math.floor(B / multi))

wC = mC - nC
wD = mD - nD
wM = mM - nM
wCD = wC + wD - wM

nGcd = int(math.floor((A - 1) / multiGcd))
mGcd = int(math.floor(B / multiGcd))
wGcD = mGcd - nGcd

ans = B - (A - 1) - wCD
if multiGcd != multi:
    ans += wGcD
print(ans)

Submission status: Runtime Error

Solution code:
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())

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

a,b,c,d = Is()
mc = b//c - (a-1)//c
md = b//d - (a-1)//d
mincom = lcm(c,d)
mcd = b//(mincom) - (a-1)//(mincom)
ans = b-a+1 - (mc + md - mcd)
#print(mc,md,mcd)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

a, b, c, d = [int(i) for i in input().split()]
#
#num = np.arange(b - a + 1) + a
#
#if b < c and b < d:
#    print('0')
#    exit(0)
#
#m = min(c, d)
#div = max(c, d)
#tmp = []
#div = num[0] // div + div
#index = 0
#while True:
#    if n[index] % div != 0:
#        if index + div >
#        tmp += range(n[index], n[index])
#        index += 1
#    else:
#        index += div
#
#tmp = np.array(tmp)
#print(tmp[tmp % m == 0].shape[0])


size = b - a + 1
cd = int(c * d // math.gcd(c, d))
c_num_a = a // c
d_num_a = a // d
cd_num_a = a // cd
c_num_b = b // c
d_num_b = b // d
cd_num_b = b // cd

c_num = c_num_b - c_num_a
d_num = d_num_b - d_num_a
cd_num = cd_num_b - cd_num_a

if a % c == 0:
    c_num += 1
if a % d == 0:
    d_num += 1

print(size - c_num - d_num + cd_num)

Submission status: Runtime Error

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

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

a,b,c,d = list(map(int,input().split(" ")))
e = lcm(c,d)
p=a//c
o=b//c
i=a//d
u=b//d
y=a//e
t=b//e
C = max([0.o-p])
D = max([0,u-i])
E = max([0,t-y])
print( (b-a+1)-(C+D-E) )

Submission status: Runtime Error

Solution code:
import sys
from io import StringIO
import unittest
import math


#from numba import jit
def lcm(x, y):
    return (x * y) // math.gcd(x, y)


def resolve():
    A, B, C, D = map(int, input().split())
    size = B - A + 1
    C_warikire = math.ceil(size / C)
    D_warikire = math.ceil(size / D)
    C_and_D_warikire = math.ceil(size / (lcm(C, D)))
    print(size - C_warikire - D_warikire + C_and_D_warikire)
resolve()

Submission status: Runtime Error

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

# n_c = 0
# n_d = 0
# n_cd = 0
# for i in range(A,B+1):
#     if(i % C == 0):
#         n_c = i // C
#     n_d = i // D
#     n_cd = i//(C*D)

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

n_c = B//C - A//C
n_d = B//D - A//D
CD = lcm(C,D)
n_cd = B//(CD) - A//(CD)

if(A%C == 0):
    n_c += 1
if(A%D==0):
    n_d += 1
if(A%CD==0):
    n_cd += 1


if (max(C,D)%min(C,D) == 0):
    ans = (B-A+1) - max(n_c, n_d)
else:
    ans = (B-A + 1) - (n_c + n_d - n_cd)

# print(n_c)
# print(n_d)
# print(n_cd)

print(ans)

Submission status: Runtime Error

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

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

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

p=a//c
o=b//c
i=a//d
u=b//d
y=a//e
t=b//e

C = max(0.o-p)
D = max(0,u-i)
E = max(0,t-y)
print((b-a+1)-(C+D-E))

Submission status: Runtime Error

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

def div (n):
    rt = lg // n
    if lg % n != 0 and ((n- a%n) + (b%n) < n):
        rt += 1
    return(rt)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import numpy as np
a,b,c,d  = map(int, input().split())
count = 0
for i in range(a, b+1):
    if (i%c != 0) & (i%d !=0):
        count+=1
    else:
        pass
print(count)

Submission status: Runtime Error

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

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

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

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 asyncio
a, b, c, d = map(int, input().split())
loop = asyncio.get_event_loop()
i = c if c < d else d
num = 0
loop_was_not_running = not loop.is_running()
async def y(q):
  global num
  if q % c and q % d:
    num += 1
    
def print_hello_world(future):
  if loop_was_not_running:
    loop.stop()

li = [y(o) for o in range(a, b)]
future = asyncio.gather(*li)
asyncio.ensure_future(future)
future.add_done_callback(print_hello_world)
    if loop_was_not_running:
        loop.run_forever()
print(num)

Submission status: Runtime Error

Solution code:
a, b, c, d = list(map(input().split(), int))
res = 0
for i in range(a+1, b+1):
  if i % c > 0 and i % d > 0:
    res += 1
print(res)

Submission status: Runtime Error

Solution code:
import math

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

A,B,C,D = [int(x) for x in input().split(' ')]
a = (B - A + 1) 
b = ((B // C) - ((A-1) // C))
c = ((B // D) - ((A-1) // D))
CD = lcm(C,D)
d = ((B // (CD)) - ((A-1) // (CD)))
q = a - b - c + d
print(q)

Submission status: Runtime Error

Solution code:
import math

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

c_div_a = (a-1) // c
# print("c_div_a:", c_div_a)
c_div_all = b // c
# print("c_div_all:", c_div_all)

# print("---")

d_div_a = (a-1) // d
# print("d_div_a:", d_div_a)
d_div_all = b // d
# print("d_div_all:", d_div_all)

# print("---")

cd_div_a = (a-1) // int( (c*d) / math.gcd(c, d) )
# print("cd_div_a:", cd_div_a)
cd_div_all = b // int( (c*d) / math.gcd(c, d) )
# print("cd_div_all:", cd_div_all)

# print("---")

div_a = c_div_a + d_div_a - cd_div_a
# print("div_a:", div_a)
div_all = c_div_all + d_div_all - cd_div_all
# print("div_all:", div_all)

print( (b - (a-1)) - (div_all - div_a) )

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)
if num != 0:
    tmp = (C * D) // num
else:
    tmp = C*D


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

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

n_c = 0
n_d = 0
n_cd = 0
# for i in range(A,B+1):
#     if(i % C == 0):
#         n_c = i // C
#     n_d = i // D
#     n_cd = i//(C*D)

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

n_c = B//C - A//C
n_d = B//D - A//D
CD = lcm(C,D)
n_cd = B//(CD) - A//(CD)

if(A%C == 0):
    n_c += 1
if(A%D==0):
    n_d += 1
if(A%CD==0):
    n_cd += 1


if (max(C,D)%min(C,D) == 0):
    ans = (B-A+1) - max(n_c, n_d)
else:
    ans = (B-A + 1) - (n_c + n_d - n_cd)

# print(n_c)
# print(n_d)
# print(n_cd)

print(ans)

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()))
p=[c,d]
p.sort()
c,d=p[0],p[1]
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:
import math
a,b,c,d=map(int,input().split())
yoso=b-a+1
kobai=math.gcd(c,d)
BC=b%c
BD=b%d
Bkobai=b%kobai
C=0
if BC>=(yoso%c):
  C=yoso//c
else:
  C=(yoso//c)+1
D=0
if BD>=(yoso%d):
  D=yoso//d
else:
  D=(yoso//d)+1
CD=0
if Bkobai>=(yoso%kobai):
  CD=yoso//kobai
else:
  CD=(yoso//kobai)+1
print(yoso+CD-C-D)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
import math

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

x = int(c * d / math.gcd(c, d))
c1d = int((a - 1) / c)
c2d = int((b + 0) / c)
d1d = int((a - 1) / d)
d2d = int((b + 0) / d)
x1d = int((a - 1) / x)
x2d = int((b + 0) / x)

print(b + 1 - a - (c2d - c1d + d2d - d1d - (x2d - x1d)))

Submission status: Runtime Error

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

if a%c==0:
    cc=int(b/c)-int(a/c)
else:
    cc = int(b / c) - (int(a / c)+1)


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

i=0
f=[c]
x=10000000
k=[c,d]

while x!=0:
    x=max(k)%min(k)

    if x!=0:
        f.append(x)
    k.sort()
    k[1]=x
#Wprint(min(f))
    if (int(b / (c*d/min(f))))!=( int(a / (c*d/min(f)))):
        if a%d==0:
            cd = int(b / (c*d/min(f)))- int(a / (c*d/min(f)))
        else:
            cd=int(b/(c*d/min(f)))-(int(a/(c*d/min(f)))+1)
        cd=0


print(b-a-cc-dd+cd)

Submission status: Runtime Error

Solution code:
if A%C==0 and A%D==0:
    C_div = (B-A+1)//C + 1
else:
    C_div = (B-A+1)//C
if B%C==0 and B%D==0:
    D_div = (B-A+1)//D + 1
else:
    D_div = (B-A+1)//D
if A%(C*D) == 0 and B%(C*D) == 0:
    CD_div = (B-A+1)//(C*D) + 1
else:
    CD_div = (B-A+1)//(C*D)
if C == 1 or D == 1:
    print(0)
elif C == D:
    print((B-A+1) - C_div)
elif C%D==0 or D%C==0:
    if C > D:
        print((B-A+1) - D_div)
    else:
        print((B-A+1) - C_div)
else:
    print((B-A+1) - C_div -D_div + CD_div)

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())
cnt = 0
for i in range(A, B+1):
  if i % C !== 0:
    if i % D !== 0:
      cnt += 1
      
print(cnt)

Submission status: Runtime Error

Solution code:
a, b, c, d=map(int, input().split())
count_cd=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_cd+=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_cd)