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


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

"""
# A以上B以下でCで割り切れる数の個数
x1 = (A-1) // C
x2 = B // C
x = x2 - x1
#print("x:", x)

# A以上B以下でDで割り切れる数の個数
y1 = (A-1) // D
y2 = B // D
y = y2 - y1
#print("y", y)

# A以上B以下でC,Dで割り切れる数の個数
z1 = (A-1) // lcm(C, D)
z2 = B // lcm(C, D)
z = z2 - z1
#print("lcm:{}".format(lcm(C, D)))
#print("z", z)

# A~B間の整数 - Cの倍数とDの倍数の個数 + CでもDでも割り切れる個数
not_d = B - (A+1) - (x + y - z)
print(int(not_d))
 """

total = b - a+1
bsep = (b // c) + (b // d) - (b // lcm(c, d))
asep = (a-1) // c + (a-1) // d - (a-1) // lcm(c, d)

ans = total - bsep + asep
print(ans)

Submission status: Runtime Error

Solution code:
import math


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


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

"""
# A以上B以下でCで割り切れる数の個数
x1 = (A-1) // C
x2 = B // C
x = x2 - x1
#print("x:", x)

# A以上B以下でDで割り切れる数の個数
y1 = (A-1) // D
y2 = B // D
y = y2 - y1
#print("y", y)

# A以上B以下でC,Dで割り切れる数の個数
z1 = (A-1) // lcm(C, D)
z2 = B // lcm(C, D)
z = z2 - z1
#print("lcm:{}".format(lcm(C, D)))
#print("z", z)

# A~B間の整数 - Cの倍数とDの倍数の個数 + CでもDでも割り切れる個数
not_d = B - (A+1) - (x + y - z)
print(int(not_d))
 """


bsep = (b // c) + (b // d) - (b // lcm(c, d))
asep = (a-1) // c + (a-1) // d - (a-1) // lcm(c, d)

ans = b - (a+1) - bsep + asep
print(ans)

Submission status: Runtime Error

Solution code:
import math


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


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

"""
# A以上B以下でCで割り切れる数の個数
x1 = (A-1) // C
x2 = B // C
x = x2 - x1
#print("x:", x)

# A以上B以下でDで割り切れる数の個数
y1 = (A-1) // D
y2 = B // D
y = y2 - y1
#print("y", y)

# A以上B以下でC,Dで割り切れる数の個数
z1 = (A-1) // lcm(C, D)
z2 = B // lcm(C, D)
z = z2 - z1
#print("lcm:{}".format(lcm(C, D)))
#print("z", z)

# A~B間の整数 - Cの倍数とDの倍数の個数 + CでもDでも割り切れる個数
not_d = B - (A+1) - (x + y - z)
print(int(not_d))
 """


bsep = (b // c) + (b // d) - (b // lcm(c, d))
asep = (a-1) // c + (a-1) // d - (a-1) // lcm(c, d)

ans = b - a+1 - bsep + asep
print(ans)

Submission status: Runtime Error

Solution code:
import math


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

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

"""
# A以上B以下でCで割り切れる数の個数
x1 = (A-1) // C
x2 = B // C
x = x2 - x1
#print("x:", x)

# A以上B以下でDで割り切れる数の個数
y1 = (A-1) // D
y2 = B // D
y = y2 - y1
#print("y", y)

# A以上B以下でC,Dで割り切れる数の個数
z1 = (A-1) // lcm(C, D)
z2 = B // lcm(C, D)
z = z2 - z1
#print("lcm:{}".format(lcm(C, D)))
#print("z", z)

# A~B間の整数 - Cの倍数とDの倍数の個数 + CでもDでも割り切れる個数
not_d = B - (A+1) - (x + y - z)
print(int(not_d))
 """





bsep = (b // c) + (b // d) - (b // lem(c, d))
asep = (a-1) // c + (a-1) // d - (a-1) // lem(c, d)

ans = total - bsep + asep
print(ans)

Submission status: Runtime Error

Solution code:
import math


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


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

# A以上B以下でCで割り切れる数の個数
x1 = (A-1) // C
x2 = B // C
x = x2 - x1
#print("x:", x)

# A以上B以下でDで割り切れる数の個数
y1 = (A-1) // D
y2 = B // D
y = y2 - y1
#print("y", y)

# A以上B以下でC,Dで割り切れる数の個数
z1 = (A-1) // lcm(C, D)
z2 = B // lcm(C, D)
z = z2 - z1
#print("lcm:{}".format(lcm(C, D)))
#print("z", z)

# A~B間の整数 - Cの倍数とDの倍数の個数 + CでもDでも割り切れる個数
not_d = B - (A+1) - (x + y - z)
print(int(not_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())

# A以上B以下でCで割り切れる数の個数
x1 = (A-1) // C
x2 = B // C
x = x2 - x1
#print("x:", x)

# A以上B以下でDで割り切れる数の個数
y1 = (A-1) // D
y2 = B // D
y = y2 - y1
#print("y", y)

# A以上B以下でC,Dで割り切れる数の個数
z1 = (A-1) // lcm(C, D)
z2 = B // lcm(C, D)
z = z2 - z1
#print("lcm:{}".format(lcm(C, D)))
#print("z", z)

# A~B間の整数 - Cの倍数とDの倍数の個数 + CでもDでも割り切れる個数
not_d = B - (A+1) - (x + y - z)
print(not_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())

# A以上B以下でCで割り切れる数の個数
x1 = (A-1) // C
x2 = B // C
x = x2 - x1
#print("x:", x)

# A以上B以下でDで割り切れる数の個数
y1 = (A-1) // D
y2 = B // D
y = y2 - y1
#print("y", y)

# A以上B以下でC,Dで割り切れる数の個数
z1 = (A-1) // lcm(C, D)
z2 = B // lcm(C, D)
z = z2 - z1
#print("lcm:{}".format(lcm(C, D)))
#print("z", z)

# A~B間の整数 - Cの倍数とDの倍数の個数 + CでもDでも割り切れる個数
not_d = B - A+1 - (x + y - z)
print(int(not_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())

# A以上B以下でCで割り切れる数の個数
x1 = (A-1) // C
x2 = B // C
x = x2 - x1
#print("x:", x)
# A以上B以下でDで割り切れる数の個数
y1 = (A-1) // D
y2 = B // D
y = y2 - y1
#print("y", y)
# A以上B以下でC,Dで割り切れる数の個数
z1 = (A-1) // lcm(C, D)
z2 = B // lcm(C, D)
z = z2 - z1
#print("lcm:{}".format(lcm(C, D)))
#print("z", z)

# A~B間の整数 - Cの倍数とDの倍数の個数 + CでもDでも割り切れる個数
not_d = B - A+1 - (x + y - z)
print(not_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())

# A以上B以下でCで割り切れる数の個数
x1 = (A-1) // C
x2 = B // C
x = x2 - x1
#print("x:", x)
# A以上B以下でDで割り切れる数の個数
y1 = (A-1) // D
y2 = B // D
y = y2 - y1
#print("y", y)
# A以上B以下でC,Dで割り切れる数の個数
z1 = (A-1) // lcm(C, D)
z2 = B // lcm(C, D)
z = z2 - z1
#print("lcm:{}".format(lcm(C, D)))
#print("z", z)

# A~B間の整数 - Cの倍数とDの倍数の個数 + CでもDでも割り切れる個数
not_d = B - A+1 - (x + y - z)
print(not_d)

Submission status: Runtime Error

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

def gcd(C, D):
  if C >= D:
    tmp = C
    C = D
    D = tmp
  gcd = 1  
  for i in range(D-C+1):
    dif_1 = D % C
    if C % dif_1 == 0:
      gcd = dif_1
      break
    D = C
    C = dif_1
  return gcd

gcd = gcd(C, D)
lcm = C * D // gcd
a_c = (A-1) // C
a_d = (A-1) // D
b_c = B // C
b_d = B // D
a_lcm = (A-1) // lcm
b_lcm = B // lcm
count = (B - A + 1) - ((b_c - a_c) + (b_d - a_d) - (b_lcm - a_lcm))
print(int(count))

Submission status: Runtime Error

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

def gcd(C, D):
  if C >= D:
    tmp = C
    C = D
    D = tmp
  gcd = 1  
  for i in range(D-C+1):
    dif_1 = D % C
    if C % dif_1 == 0:
      gcd = C
      break
    D = C
    C = dif_1
  return gcd

gcd = gcd(C, D)
lcm = C * D // gcd
a_c = (A-1) // C
a_d = (A-1) // D
b_c = B // C
b_d = B // D
a_lcm = (A-1) // lcm
b_lcm = B // lcm
count = (B - A + 1) - ((b_c - a_c) + (b_d - a_d) - (b_lcm - a_lcm))
print(int(count))

Submission status: Runtime Error

Solution code:
import math

A,B,C,D = map(int, input().split())
B_C = B // C
B_D = B // D
g = math.gcd(C,D)
l = C * D / g
duplicate_B = B // l
answer_B = B - B_C - B_D + duplicate_B

A_C = (A - 1) // C
A_D = (A - 1) // D
duplicate_A = (A - 1) // l
answer_A = (A - 1) - A_C - A_D + duplicate_A
print(int(answer_B - answer_A))

Submission status: Runtime Error

Solution code:
import sys
import math
input = sys.stdin.readline
def lcm(x, y):
  return (x * y) // math.gcd(x, y)


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


print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
input = sys.stdin.readline
def lcm(x, y):
    return (x * y) // math.gcd(x, y)


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


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())
re=[]
cd=lcm(c, d)

cc=int(b/c - a/c)
dc=int(b/d - a/d)
cdc=int(b/cd - a/cd)

print(b-a-cc-dc+cdc)

Submission status: Runtime Error

Solution code:
import math ##the version before 3.4 : import fractions

d = [int(x) for x in input().split()]
print(d[1] - d[0] + 1 - (int(d[1] // d[2]) - int((d[0] - 1) // d[2]) + int(d[1] // d[3]) - int((d[0] - 1) // d[3]) - int(d[1] // (d[2] * d[3] // math.gcd(d[2], d[3]))) - int((d[0] - 1) // (d[2] * d[3]// math.gcd(d[2], d[3])))))

Submission status: Runtime Error

Solution code:
import fraction

d = [int(x) for x in input().split()]
print(d[1] - d[0] + 1 - (int(d[1] / d[2]) - int((d[0] - 1) / d[2]) + int(d[1] / d[3]) - int((d[0] - 1) / d[3]) - int(d[1] / (d[2] * d[3] / fraction.gcd(d[2], d[3]))) - int((d[0] - 1) / (d[2] * d[3]/ fraction.gcd(d[2], d[3])))))

Submission status: Runtime Error

Solution code:
import math

d = [int(x) for x in input().split()]
print(d[1] - d[0] + 1 - (int(d[1] / d[2]) - int((d[0] - 1) / d[2]) + int(d[1] / d[3]) - int((d[0] - 1) / d[3]) - int(d[1] / (d[2] * d[3] / math.gcd(d[2], d[3]))) - int((d[0] - 1) / (d[2] * d[3]/ math.gcd(d[2], d[3])))))

Submission status: Runtime Error

Solution code:
L, R = map(int, input().split())

ans = 2019
for i in range(L, R):
    f = False
    for j in range(i, R):
        if  ((i*j) % 2019) == 0:
            print(0)
            break
        ans = min(ans, (i*j)%2019)
    if f:
        break
print(ans)

Submission status: Runtime Error

Solution code:
import math

# a ~ bでcの倍数の個数を返す
def count_maltiple(a, b, c):
    if a == b:
        if a == b and a%c == 0:
            return 1
        else:
            return 0
    else:
        if a%c == 0:
            st = a
        else:
            st = a + c - a%c

        if (b - b%c) - st < 0:
            return 0
        else:
            return int(((b - b%c) - st)/c + 1)
        
def lcm(c, d):
    return c*d // math.gcd(c,d)


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

Submission status: Runtime Error

Solution code:
import math

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

# a ~ bでcの倍数の個数を返す
def count_maltiple(a, b, c):
    if a == b:
        if a == b and a%c == 0:
            return 1
        else:
            return 0
    else:
        if a%c == 0:
            st = a
        else:
            st = a + c - a%c

        if (b - b%c) - st < 0:
            return 0
        else:
            return int(((b - b%c) - st)/c + 1)
        
def lcm(c, d):
    return c*d / math.gcd(c,d)

print(b - a +1 - (count_maltiple(a,b,c) + count_maltiple(a,b,d) - count_maltiple(a,b,lcm(c,d))))

# # 以下だと時間切れ
# for i in range(a, b+1):
#     if i%c == 0 and i%d == 0:
#           cnt += 1
# print(cnt)

Submission status: Runtime Error

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

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

a_cnt = (A -1) - (((A - 1) // C) + ((A - 1) // D) - ((A - 1) // (lcm)))
b_cnt = B - ((B // C) + (B // D) - (B // (lcm)))

print(b_cnt - a_cnt)

Submission status: Runtime Error

Solution code:
import math

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

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

ans_A = int((A-1) - (A-1)//C - (A-1)//D + (A-1)//lcm)
ans_B = int(B - B//C - B//D + B//lcm)
print(ans_B - ans_A)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math


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

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

maxC = B // C
maxD = B // D
maxlcm = B // lcm

minC = (A-1) // C
minD = (A-1) // D
minlcm = (A-1) // lcm

lcmB = (maxC + maxD - maxlcm)
lcmA = (minC + minD - minlcm)

print((B-A+1)-(lcmB-lcmA))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math


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

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

maxC = B // C
maxD = B // D
maxlcm = B // lcm

minC = (A-1) // C
minD = (A-1) // D
minlcm = (A-1) // lcm

lcmB = (maxC + maxD - maxlcm)
lcmA = (minC + minD - minlcm)

print(lcmB)
print(lcmA)
print((B-A+1)-(lcmB-lcmA))

Submission status: Runtime Error

Solution code:
import math

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

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

comp = int(((lcm//C) + (lcm//D) - 1) * ((B-A+1)//lcm))

for i in range((B-A+1)%lcm):
    if (A+i)%C == 0 or (A+i)%D == 0:
        comp += 1

print(B-A+1-comp)

Submission status: Runtime Error

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

#b以下について
c1 = b // c
d1 = b // d
gcd = math.gcd(c, d)
lcm = c * d // gcd
lcm1 = b // lcm
b1 = b - c_ - d_ + lcm_

c2 = (a-1) // c
d2 = (a-1) // d
lcm2 = (a-1) // lcm
a1 = a - 1 - c_ - d_ + lcm_
print(b1 - a1)

Submission status: Runtime Error

Solution code:
import fractions

abcd = list(map(int, input().split()))
a = abcd[0]
b = abcd[1]
c = abcd[2]
d = abcd[3]

aa = a - 1
lcm = (c * d) // fractinos.gcd(c, d)

a_count = aa - (aa // c) - (aa // d) + (aa // lcm)
b_count = b - (b // c) - (b // d) + (b // lcm)

print(b_count - a_count)

Submission status: Runtime Error

Solution code:
x=input().split()
x=[int(i) for i in x]

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


C1=B//C
D1=B//D

C2=(A-1)//C
D2=(A-1)//D

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

lcm1=B//lcm
lcm2=(A-1)//lcm
#print(lcm1,lcm2)

ans=B-A-C1+C2-D1+D2+lcm1-lcm2+1

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())
ab = B - A
p1 = ab // C
p2 = ab // D
p3 = ab // lcm(C, D)

print(ab - p1-p2+p3)

Submission status: Runtime Error

Solution code:
import math
x = input().split()
a,b,c,d = int(x[0]),int(x[1]),int(x[2]),int(x[3])

cn=0
if a%c==0:
    cn+=1
cn+=int(b/c)-int(a/c)
dn=0
if a%d==0:
    dn+=1
dn+=int(b/d)-int(a/d)

cdn=0
cd = c*d/math.gcd(c,d)
if a%cd==0:
    cdn+=1
cdn+=int(b/cd)-int(a/cd)

print((b-a+1)-(cn+dn-cdn))

Submission status: Runtime Error

Solution code:
import math

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

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

if A == 0:
	t1 = 0
else:
	t1 = A - (A/C + A/D - A/lcm)

t2 = B - (B/C + B/D - B/lcm)
print(int(t2 - t1))

Submission status: Runtime Error

Solution code:
import math

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

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

if A == 0:
	t1 = 0
else:
	t1 = A - (A//C + A//D - A//lcm)

t2 = B - (B//C + B//D - B//lcm)
print(t2 - t1)

Submission status: Runtime Error

Solution code:
import math

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

lcm = (C*D)//math.gcd(A, D)
A = A-1
t1 = A - (A//C + A//D - A//lcm)
t2 = B - (B//C + B//D - B//lcm)
print(t2 - t1)

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

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

yaku_b = b - (b // c + b // d - b // lcm(c,d))
yaku_a = a-1 - ((a-1) // c + (a-1) // d - (a-1) // lcm(c,d))
print(yaku_b - yaku_a)

Submission status: Runtime Error

Solution code:
#整数 A,B,C,D が与えられます。A 以上 B 以下の整数のうち、C でも D でも割り切れないものの個数を求めてください。
#B 以下の整数の個数 (B 個) から、B 以下の C の倍数の個数と B 以下の D の倍数の個数を引き、
#重複して引いたものを足し戻す
import math

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

#B以下のCの倍数の数
if A%C==0 or B%C==0:
    c = B//C - A//C + 1
else:
    c = B//C - A//C
#B以下のDの倍数の数
if A%D==0 or B%C==0:
    d = B//D - A//D + 1
else:
    d = B//D - A//D 
#重複分（最小公倍数）
x = C*D//math.gcd(C,D)
if A%x == 0 or B%x == 0:
    cd = B//x - A//x +1
else:
    cd = B//x - A//x

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

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

_ac = (a-1) // c # a以下のcの倍数の数
_bc = b // c # b以下のcの倍数の数

_ad = (a-1) // d # a以下のdの倍数の数
_bd = b // d # b以下のdの倍数の数

_acd = (a-1) // lcm(c,d) # a以下のcdの倍数の数
_bcd = b // lcm(c,d) # b以下のcdの倍数の数

m = (b-a+1) - ((_bc-_ac) + (_bd-_ad) - (_bcd-_acd))
print(m)

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

_ac = (a-1) // c
_bc = b // c

_ad = (a-1) // d
_bd = b // d

_acd = (a-1) // lcm(c,d)
_bcd = b // lcm(c,d)

m = (b-a+1) - ((_bc-_ac) + (_bd-_ad) - (_bcd-_acd))
print(m)

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

_ac = (a-1) // c # a以下のcの倍数の数
_bc = b // c # b以下のcの倍数の数

_ad = (a-1) // d # a以下のdの倍数の数
_bd = b // d # b以下のdの倍数の数

_acd = (a-1) // lcm(c,d) # a以下のcdの倍数の数
_bcd = b // lcm(c,d) # b以下のcdの倍数の数

m = (b-a+1) - ((_bc-_ac) + (_bd-_ad) - (_bcd-_acd))
print(m)

Submission status: Runtime Error

Solution code:
def gcd(x, y):  # ユークリッドの互除法
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


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


def num(n, c, d):
    c = n // c
    d = n // d
    cd = n // (lcm(c, d))
    return n - c - d + cd


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

Submission status: Runtime Error

Solution code:
import math


def main():
    min_num, max_num, C, D = map(int, input().split())
    diff_C = aida_num(max_num, min_num, C)
    diff_D = aida_num(max_num, min_num, D)
    diff_CD = aida_num(max_num, min_num, lcm(C, D))

    # print(diff_C, diff_D, diff_CD)

    diff = diff_C + diff_D - diff_CD
    print(max_num - min_num + 1 - diff)


def aida_num(max_num: int, min_num: int, target: int):
    return math.floor(max_num / target) - math.ceil(min_num / target) + 1


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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

large_c = b // c
large_d = b // d
large_cd = b // ((c * d) / math.gcd(c, d))
large = large_c + large_d - large_cd

small_c = (a - 1) // c
small_d = (a - 1) // d
small_cd = (a - 1) // ((c * d) / math.gcd(c, d))
small = small_c + small_d - small_cd

print(int((b - (a - 1)) - (large - small)))

Submission status: Runtime Error

Solution code:
#include <stdio.h>
int main(){
  int a,b,c,d,i=0,ans=0;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  for(i=a;i<=b;i++){
    if((i%c!=0)&&(i%d!=0)){
      ans++;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Submission status: Runtime Error

Solution code:
from fraction import lcm

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

Submission status: Runtime Error

Solution code:
import math

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


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


one_to_b = B - ((B // C) + (B // D) - (B // lcm(C, D)))
one_to_a = A - 1 - ((((A - 1) // C) +
                     ((A - 1) // D) -
                     (A - 1) // lcm(C, D)))

print(one_to_b - one_to_a)

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
x = b // c
y = b // d
w = b //(c　* d)
z = (a - 1) // d
v = (a - 1) // c
h = (a - 1) // (c * d)
print((b - x - y + w) - ((a-1) - z - v + h))
print(x,y,v,z)

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
x = b // c
y = b // d
w = b //(c　* d)
z = (a - 1) // d
v = (a - 1) // c
h = (a - 1) // (c * d)
print((b - x - y - w) - ((a-1) - z - v - h))
print(x,y,v,z)

Submission status: Runtime Error

Solution code:
A, B, C, D = map(int, input().split())
def GCD(x,y):
  if x%y==0:
    return y
  else:
    return GCD(y, x%y)
def lcm(x, y):
    return (x * y) // gcd(x, y)
E = lcm(C, D)
answer = (B-A) - (B//C) - (B//D) + (B//E) + (A//C) + (A//D) - (A//E)
if A%C==0 or A%D==0:
  print(answer)
else:
  print(answer + 1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
A, B, C, D = map(int, input().split())
def GCD(x,y):
  if x%y==0:
    return y
  else:
    return GCD(y, x%y)
GCD(1071, 1029)
def lcm(x, y):
    return (x * y) // gcd(x, y)
  
E = lcm(C, D)
answer = (B-A) - (B//C) - (B//D) + (B//E) + (A//C) + (A//D) - (A//E)
if A%C==0 or A%D==0:
  print(answer)
else:
  print(answer + 1)

Submission status: Runtime Error

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

gcd = fractions.gcd(C, D)

lcm = C * D / gcd

ac = A/C
bc = B/C
ad = A/D
bd = B/D
acd = A/lcm
bcd = B/lcm

if A%C != 0:
    ac = int(ac) + 1
if B%C != 0:
    bc = int(bc)
if A%D != 0:
    ad = int(ad) + 1
if B%D != 0:
    bd = int(bd)
if A%lcm != 0:
    acd = int(acd) + 1
if B%lcm != 0:
    bcd = int(bcd)

    
c_n = bc - ac + 1
d_n = bd - ad + 1
cd_n = bcd - acd + 1

ans = B - A + 1 - c_n - d_n + cd_n
print(int(ans))

Submission status: Runtime Error

Solution code:
import math

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

gcd = math.gcd(C, D)

lcm = C * D / gcd

ac = A/C
bc = B/C
ad = A/D
bd = B/D
acd = A/lcm
bcd = B/lcm

if A%C != 0:
    ac = int(ac) + 1
if B%C != 0:
    bc = int(bc)
if A%D != 0:
    ad = int(ad) + 1
if B%D != 0:
    bd = int(bd)
if A%lcm != 0:
    acd = int(acd) + 1
if B%lcm != 0:
    bcd = int(bcd)

    
c_n = bc - ac + 1
d_n = bd - ad + 1
cd_n = bcd - acd + 1

ans = B - A + 1 - c_n - d_n + cd_n
print(int(ans))

Submission status: Runtime Error

Solution code:
import math

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

gcd = math.gcd(C, D)

lcm = C * D / gcd

ac = A/C
bc = B/C
ad = A/D
bd = B/D
acd = A/lcm
bcd = B/lcm

if A%C != 0:
    ac = int(ac) + 1
if B%C != 0:
    bc = int(bc)
if A%D != 0:
    ad = int(ad) + 1
if B%D != 0:
    bd = int(bd)
if A%lcm != 0:
    acd = int(acd) + 1
if B%lcm != 0:
    bcd = int(bcd)

    
c_n = bc - ac + 1
d_n = bd - ad + 1
cd_n = bcd - acd + 1

ans = B - A + 1 - c_n - d_n + cd_n
    
print(int(ans))

Submission status: Runtime Error

Solution code:
A, B, C, D = map(int, input().split())
from math import gcd
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
E = lcm(C, D)
answer = (B-A) - (B//C) - (B//D) + (B//E) + (A//C) + (A//D) - (A//E)

Submission status: Runtime Error

Solution code:
import math

inputs = [int(i) for i in input().split()]

counter = 0

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

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

l = lcm(c, d)

c1 = b // c
c2 = (a-1) // c
c3 = c1 - c2

d1 = b // d
d2 = (a-1) // d
d3 = d1 - d2

l1 = b // l

ans = (b-a+1) - (c3 + d3 - l1)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

adivc = A//C
if A%C != 0:
    adivc = A//C + 1
bdivc = B//C
countC = bdivc - adivc + 1

adivd = A//D
if A%D != 0:
    adivd = A//D + 1
bdivd = B//D
countD = bdivd - adivd + 1

lcm = (int)(C * (D / math.gcd(C, D)))
adivlcm = A // lcm
if A%lcm != 0:
    adivlcm = A // lcm + 1
bdivlcm = B // lcm
countlcm = bdivlcm - adivlcm + 1

print(B-A+1-(countC+countD-countlcm))

Submission status: Runtime Error

Solution code:
import math

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

adivc = A//C
if A%C != 0:
    adivc = A//C + 1
bdivc = B//C
countC = bdivc - adivc + 1

adivd = A//D
if A%D != 0:
    adivd = A//D + 1
bdivd = B//D
countD = bdivd - adivd + 1

lcm = (int)(C * D / math.gcd(C, D))
adivlcm = A // lcm
if A%lcm != 0:
    adivlcm = A // lcm + 1
bdivlcm = B // lcm
countlcm = bdivlcm - adivlcm + 1

print(B-A+1-(countC+countD-countlcm))

Submission status: Runtime Error

Solution code:
import math

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

adivc = A//C
if A%C != 0:
    adivc = A//C + 1
bdivc = B//C
print(adivc,bdivc)
countC = bdivc - adivc + 1

adivd = A//D
if A%D != 0:
    adivd = A//D + 1
bdivd = B//D
print(adivd,bdivd)
countD = bdivd - adivd + 1

lcm = (int)(C * D / math.gcd(C, D))
adivlcm = A // lcm
if A%lcm != 0:
    adivlcm = A // lcm + 1
bdivlcm = B // lcm
countlcm = bdivlcm - adivlcm + 1

print(B-A+1-(countC+countD-countlcm))

Submission status: Runtime Error

Solution code:
import math

A,B,C,D = map(int,input().split())
#print(A,B,C,D)
lcm = C * D / math.gcd(C,D)
count = 0
for i in range(A,B+1):
    if i%lcm != 0:
        count+=1
print(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())
e = b - int(b / c) - int(b / d) + int(b / lcm(c, d))
f = (a - 1) - int((a - 1) / c) - int((a - 1) / d) + int((a - 1) / lcm(c, d))
print(e - f)

Submission status: Runtime Error

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

def main():
    A,B,C,D=map(input().split())
    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:
import math

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

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

# cで割り切れる数の個数
div_c = math.floor(b / c) - math.floor((a-1) / c)
# dで割り切れる数の個数
div_d = math.floor(b / d) - math.floor((a-1) / d)
# cdの最小公倍数で割り切れる数の個数
div_com = math.floor(b / lcm(c, d)) - math.floor((a-1) / lcm(c, d))
# a～bまで c or d で割り切れる数
sum = div_c + div_d - div_com

print(b-a+1-sum)

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で割り切れる数の個数
div_c = math.floor(b / c) - math.floor((a-1) / c)
# dで割り切れる数の個数
div_d = math.floor(b / d) - math.floor((a-1) / d)
# cdの最小公倍数で割り切れる数の個数
div_com = math.floor(b / lcm(c, d)) - math.floor((a-1) / lcm(c, d))
# a～bまで c or d で割り切れる数
sum = div_c + div_d - div_com

print(b-a+1-sum)

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の約数の個数
div_c = math.floor(b / c) - math.floor(a / c)
# dの約数の個数
div_d = math.floor(b / d) - math.floor(a / d)
# cdの最小公倍数の個数
div_com = math.floor(b / lcm(a, b)) - math.floor(a / lcm(a, b))
# a～bまで c or d で割り切れる数
sum = div_c + div_d - div_com

print(b-a+1-sum)

Submission status: Runtime Error

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



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

b_c = int(b / c)
b_d = int(b / d)

l_b = int(b / g)

ans_b = b - b_c - b_d + l_b

a_c = int((a-1) / c)
a_d = int((a-1) / d)

l_a = int((a-1) / g)

ans_a = (a - 1) - a_c - a_d + l_a

print(ans_b - ans_a)

Submission status: Runtime Error

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

cs = math.ceil(a / c)
ds = math.ceil(a / d)

w = np.zeros((b + 1))

x = int(c * cs)
while x <= b:
    w[x] = 1
    x += c

y = int(d * ds)
while y <= b:
    w[y] = 1
    y += d

print(int(len(w) - a - w.sum()))

Submission status: Runtime Error

Solution code:
import fractions

def lcm(x, y):
    return (x * y) // math.gcd(x, y)
A,B,C,D = input().split()
A = int(A)-1
s = fractions.lcm(int(C),int(D))
#s = int(C)*int(D)
#numac = int(A)//int(C)#10//6 = 1
#numad = int(A)//int(D)#10//8 = 1
#numacd = int(A)//s#10//24 = 0
numa = int(A)//int(C) + int(A)//int(D) - int(A)//s
#numa = 1
#numbc = int(B)//int(C)#40//6 = 6
#numbd = int(B)//int(D)#40//8 = 5
#numbcd = int(B)//s#40//24= 1
numb = int(B)//int(C) + int(B)//int(D) - int(B)//s
#numb = 1
print(int(B)-int(A)-(numb - numa))

Submission status: Runtime Error

Solution code:
import math
import psutil

def lcm(x, y):
    return (x * y) // math.gcd(x, y)
A,B,C,D = input().split()
A = int(A)-1
s = lcm(int(C),int(D))
#s = int(C)*int(D)
#numac = int(A)//int(C)#10//6 = 1
#numad = int(A)//int(D)#10//8 = 1
#numacd = int(A)//s#10//24 = 0
numa = int(A)//int(C) + int(A)//int(D) - int(A)//s
#numa = 1
#numbc = int(B)//int(C)#40//6 = 6
#numbd = int(B)//int(D)#40//8 = 5
#numbcd = int(B)//s#40//24= 1
numb = int(B)//int(C) + int(B)//int(D) - int(B)//s
#numb = 1
print(int(B)-int(A)-(numb - numa))

Submission status: Runtime Error

Solution code:
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
A,B,C,D = input().split()
A = int(A)-1
s = lcm(int(C),int(D))
numac = int(A)//int(C)#10//6 = 1
numad = int(A)//int(D)#10//8 = 1
numacd = int(A)//s#10//24 = 0
numbc = int(B)//int(C)#40//6 = 6
numbd = int(B)//int(D)#40//8 = 5
numbcd = int(B)//s#40//24= 1
print(int(B)-int(A)-(numbc+numbd-numbcd -(numac+numad-numacd)))

Submission status: Runtime Error

Solution code:
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
A,B,C,D = input().split()
A = int(A)-1
numac = int(A)//int(C)#10//6 = 1
numad = int(A)//int(D)#10//8 = 1
numacd = int(A)//(lcm(int(C),int(D)))#10//24 = 0
numbc = int(B)//int(C)#40//6 = 6
numbd = int(B)//int(D)#40//8 = 5
numbcd = int(B)//lcm(int(C),int(D))#40//24= 1
#print(numbc+numbd-numbcd )
#print(numac+numad-numacd)
#print(numbc+numbd-numbcd -(numac+numad-numacd))
t = numbc+numbd-numbcd -(numac+numad-numacd)
print(int(B)-int(A)-(numbc+numbd-numbcd -(numac+numad-numacd)))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import math

def solve(A: int, B: int, C: int, D: int):
    def can_div_by(x: int):
        return (B // x) - (A - 1) // x

    c = can_div_by(C)
    d = can_div_by(D)
    cd = can_div_by(C*D // math.gcd(C, D))
    return B - A + 1 - (c + d - cd)

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    print(solve(A, B, C, D))

if __name__ == '__main__':
    main()