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:
from math import gcd
a = list(map(int,input().split()))

def fun(x,c,d):
    return x - div(x,c) - div(x,d) + div(x,c*d//gcd(c,d))

def div(a,b):
    return a // b

print(fun(a[1],a[2],a[3])-fun(a[0]-1,a[2],a[3]))

Submission status: Runtime Error

Solution code:
from math import gcd
a,b,c,d=map(int,input().split())
ans=(b-a+1)
lcm=(c*d)//gcd(c,d)
dba=(a//c-int(a%c==0))+(a//d-int(a%d==0))-(a//lcm-int(a%lcm==0))
dbb=(b//c)+(b//d)-(b//lcm)
dbb-=dba
ans-=dbb
print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
from math import gcd
a,b,c,d=map(int,input().split())
ans=(b-a+1)
lcm=(c*d)//gcd(c,d)
dba=(a//c-int(a%c==0))+(a//d-int(a%d==0))-(a//lcm-int(a%lcm==0))
dbb=(b//c)+(b//d)-(b//lcm)
dbb-=dba
ans-=dbb
print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
from math import gcd
a,b,c,d=map(int,input().split())
ans=(b-a+1)
lcm=(c*d)//gcd(c,d)
dba=(a//c-int(a%c==0))+(a//d-int(a%d==0))-(a//lcm-int(a%lcm==0))
dbb=(b//c)+(b//d)-(b//lcm)
dbb-=dba
ans-=dbb
print(ans)

Submission status: Runtime Error

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

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

def main():
    left = (b -int(b/c) -int(b/d) +int(b/lcm(c,d)))
    right = ((a-1) -int((a-1)/c) -int((a-1)/d) +int((a-1)/lcm(c,d)))
    print(left - right)
main()

Submission status: Runtime Error

Solution code:
import numpy

"""

+ その範囲の6の倍数の数
+ その範囲の8の倍数の数
- その範囲の48の倍数の数
で答えが求まる

"""

def v_count(n, start, end):
  start_pop = start % n
  start = start + (n - start_pop)
  return int((end - start) / n) + 1

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

all_count = B - A + 1

c_count = v_count(C, A, B)
d_count = v_count(D, A, B)
min_cd = numpy.lcm(C, D)
cd_count = v_count(min_cd, A, B)

print(all_count - c_count - d_count + cd_count)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
def k(n):
    aa=n//c
    bb=n//d
    f=n//((c*d)//math.gcd(c,d))
    return n-aa-bb+f
print(k(b)-k(a-1))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

count_b = b - b//c - b//d + b//lcm(c,d)
count_a = a-1 - (a-1)//c - (a-1)//d + (a-1)//lcm(c,d)
print(count_b-count_a)

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)

count_b = b - b//c - b//d + b//lcm(c,d)
count_a = a-1 - (a-1)//c - (a-1)//d + (a-1)//lcm(c,d)
print(count_b-count_a)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import os, sys, re, math

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

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

minC = (A + (C - 1)) // C
maxC = B // C

minD = (A + (D - 1)) // D
maxD = B // D

CD = lcm(C, D)
minCD = (A + (CD - 1)) // CD
maxCD = B // CD

countC = maxC - minC + 1
countD = maxD - minD + 1
countCD = maxCD - minCD + 1

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

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
t1 = b//c-a//c
if a%c == 0:
    t1 += 1
t2 = b//d-a//d
if a%d == 0:
    t2 += 1
lcm = c*d//math.gcd(c,d)
t3 = b//lcm-a//lcm
if a%lcm == 0:
    t3 += 1
print(b-a+1-(t1+t2-t3))

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())
d1=math.floor(b/c)
d2=math.floor(b/d)
d3=math.floor(b/lcm(c,d))

d4=math.floor((a-1)/c)
d5=math.floor((a-1)/d)
d6=math.floor((a-1)/lcm(c,d))

ansb=b-(d1+d2-d3)
ansa=a-1-(d1+d2-d3)
print(ansb-ansa)

Submission status: Runtime Error

Solution code:
import math

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

def cnt(x,y,z):
    if x%z==0:
        return (y//z)-(x//z)+1
    else:
        return (y//z)-(x//z)
        
a,b,c,d=map(int,input().split())
s=lcm(c,d)
d1=cnt(a,b,c)
d2=cnt(a,b,d)
d3=cnt(a,b,s)

ans=(b-a+1)-(d1+d2-d3)
print(ans)

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
from fractions import gcd
cd_gcd = gcd(c,d)
lcm= c*d // ab_gcd
divs = lcm//c + lcm//d - 1

ans = 0
ans += int((b-a)/lcm)*divs
for i in range(a % lcm, b%lcm+lcm+1):
  if not i % c or not i % d:
    ans += 1
print(b-a - ans)

Submission status: Runtime Error

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

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

ret_b = b - (b // c + b // d - b // f)
ret_a = (a - 1) - ((a - 1) // c + (a - 1) // d - (a - 1) // f)
ans = ret_b - ret_a
print(ans)

Submission status: Runtime Error

Solution code:
A,B,C,D=map(int,input().split())
s=0
for i in range(A,B+1):
  if i%C!=0 and i$D!=0:
    s+=1
print(s)

Submission status: Runtime Error

Solution code:
import math
    
a,b,c,d = map(int,input().split())
cd = c*d//math.gcd(c, d)
 
c1 = b//c
d1 = b//d
cd1 = b//(cd)
 
c2 = (a-1)//c
d2 = (a-1)//d
cd2 = (a-1)//cd
 
c3 = c1-c2
d3 = d1-d2
cd3 = cd1-cd2
 
print(b-a+1-c3-d3+cd3)

Submission status: Runtime Error

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

c1 = b//c
d1 = b//d
cd1 = b//(cd)

c2 = (a-1)//c
d2 = (a-1)//d
cd2 = (a-1)//cd

c3 = c1-c2
d3 = d1-d2
cd3 = cd1-cd2

print(b-a+1-c3-d3+cd3)

Submission status: Runtime Error

Solution code:
from math import gcd, floor

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

def calc(n: int, x: int, y: int) -> int:
    return n - floor(n / x) - floor(n / y) + floor(n / lcm(x, y))


a, b, c, d = [int(i) for i in input().split()]
print(calc(b, c, d) - calc(a - 1, c, d))

Submission status: Runtime Error

Solution code:
from math import gcd

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

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

bc = B//C
ac = (A-1)//C
bd = B//D
ad = (A-1)//D
bcd = B//lcm(C,D)
acd = (A-1)//lcm(C,D)

print(B-A-bc+ac-bd+ad+bcd-acd+1)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
H = list(map(int,input().split()))
flag = 0
for i in range(N-2,1):
  if H[i+1]-H[i] == 0:
    continue
  else:    
    if H[i] == H[i+1]+1:
      H[i] -= 1
      continue
    else:
      print("No")
      flag += 1
      print(i)
      break
if flag == 0:
  print("Yes",i)

Submission status: Runtime Error

Solution code:
a, b, c, d  = map(int, input().split())
import math
divc = (b-a)//c
if a % c == 0:
    divc += 1
if b % c == 0:
    divc += 1
if a % c == 0 and b % c == 0:
    divc -= 1
if b-a<c:
    divc += 1

divd = (b-a)//d
if a % d == 0:
    divd += 1
if b % d == 0:
    divd += 1
if a % d == 0 and b % d == 0:
    divd -= 1   
if b-a<d:
    divd += 1

gcd = math.gcd(c,d)
cd = c * d // gcd
divcd = (b-a)//cd
if a % cd == 0:
    divcd += 1
if b % cd == 0:
    divcd += 1
if a % cd == 0 and b % cd == 0:
    divcd -= 1 
if b-a<cd:
    divcd += 1
wareru = divc + divd - divcd
ans = b - a - wareru +1
print(ans)

Submission status: Runtime Error

Solution code:
A, B, C, D = map(int, input().split())
print(
  len(set(list(range(A, B+1)))
      - set(list(range(C, B+1, C)))
      - set(list(range(D, B+1, D))))
)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
dev = b- a +1
if dev % c==0:
    count = dev//c
else:
    if ((a%c)+(b%c)) < c:
        count = dev//c +1
    else:
        count = dev//c

if dev % d==0:
    count += dev//d
else:
    if ((a%d)+(b%d)) < d:
        count += dev//d +1
    else:
        count += dev//d

def lcm(c,d):
    return (c*d)//(math.gcd(c,d))
da = lcm(c,d)
if dev % (da)==0:
    count -= int(dev/(da))
else:
    if ((a%c)+(b%c)) < (da):
        count -= int(dev/(da)) 
    else:
        count -= int(dev/(da))
print(int(dev-count))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
dev = b- a +1
if dev % c==0:
    count = dev//c
else:
    if ((a%c)+(b%c)) < c:
        count = dev//c +1
    else:
        count = dev//c

if dev % d==0:
    count += dev//d
else:
    if ((a%d)+(b%d)) < d:
        count += dev//d +1
    else:
        count += dev//d
        
da = lcm(c,d)
if dev % (da)==0:
    count -= int(dev/(da))
else:
    if ((a%c)+(b%c)) < (da):
        count -= int(dev/(da)) 
    else:
        count -= int(dev/(da))
print(int(dev-count))

Submission status: Runtime Error

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

p=a-((a//c)+(a//d)-(a//y))

q=b-((b//c)+(b//d)-(b//y))

print(int(q-p))

Submission status: Runtime Error

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

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

def ans_cnt(i,y,z):
    return i - (i//y + i//z - i//lcm(y,z))

print(ans_cnt(b,c,d)-ans_cnt(a-1,c,d))

Submission status: Runtime Error

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

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

def ans_cnt(i,y,z):
    return i - (i//y + i//z - i//lcm(y,z))

print(ans_cnt(b,c,d)-ans_cnt(a-1,c,d))

Submission status: Runtime Error

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

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

    def ans_cnt(i,y,z):
        return i - (i//y + i//z - i//lcm(y,z))
    
except EOFError:
    pass

print(ans_cnt(b,c,d)-ans_cnt(a-1,c,d))

Submission status: Runtime Error

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

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

    def ans_cnt(i,y,z):
        return i - (i//y + i//z - i//lcm(y,z))

    print(ans_cnt(b,c,d)-ans_cnt(a-1,c,d))
except EOFError:
    break

Submission status: Runtime Error

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

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

    def ans_cnt(i,y,z):
        return i - (i//y + i//z - i//lcm(y,z))

    print(ans_cnt(b,c,d)-ans_cnt(a-1,c,d))
except EOFError:
    pass

Submission status: Runtime Error

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

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

def ans_cnt(i,y,z):
    return i - (i//y + i//z - i//lcm(y,z))

print(ans_cnt(b,c,d)-ans_cnt(a-1,c,d))

Submission status: Runtime Error

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

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

def ans_cnt(i,y,z):
    return i - (i//y + i//z - i//lcm(y,z))

print(ans_cnt(b,c,d)-ans_cnt(a-1,c,d))

Submission status: Runtime Error

Solution code:
a,b,c,d=list(map(int,input().split()))
p=list(range(a,b+1))
q=list(filter(lambda x:x%c!=0 and x%d!=0,p))
print(len(q))

Submission status: Runtime Error

Solution code:
a,b,c,d=list(map(int,input().split()))
p=list(range(a,b+1))
q=list(filter(lambda x:x%2!=0 and x%3!=0,p))
print(len(q))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
e = c*d//math.gcd(c,d)
n = b-a+1
nc = (n+a%c)//c
nd = (n+a%d)//d
ne = (n+a%e)//e
print(n-(nc+nd-ne))

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
a,b,c,d=map(int,input().split())
for i in range(a,b+1):
    if i%c!=0 and i%d!=0:
        ans+=1
print(sum(1 for i in range(a,b+1) if i%c!=0 and i%d!=0 ))

Submission status: Runtime Error

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

a_c = (a-1)//c
a_d = (a-1)//d
a_cd = (a-1)//(c*d//gcd(c,d))

b_c = b//c
b_d = b//d
b_cd = b//(c*d//gcd(c,d))

bb = b - (b_c + b_d - b_cd) 
aa = (a-1) - (a_c + a_d - a_cd)

print(bb - aa)

Submission status: Runtime Error

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

x = c*d/math.gcd(c,d)
A = (a-1) - (a-1)//c - (a-1)//d +x
B = b - (b-1)//c - (b-1)//d +x
print(int(B-A))

Submission status: Runtime Error

Solution code:
import fractions

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

Submission status: Runtime Error

Solution code:
import math


def main():
    a, b, c, d = map(int, input().split())
    l =  (c * d) // math.gcd(c, d)
    cntb = b - (b // c + b // d - b // l)
    cnta = (a-1) - ((a-1) // c + (a-1) // d - (a-1) // l)
    ans = cntb - cnta

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

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

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

n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = b//lcm - (a-1)//lcm

print(n - n_c - n_d + n_cd)

Submission status: Runtime Error

Solution code:
import math

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

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

n_c = b // c - (a-1)//c
n_d = b // d - (a-1)//d
n_cd = b // lcm - (a-1)//lcm

print(n - n_c - n_d + n_cd)

Submission status: Runtime Error

Solution code:
import math

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

ac_r = a % c
ad_r = a % d
lcm =  (c*d) // math.gcd(c, d)
acd_r = a % lcm
n = b - a + 1

if (ac_r == 0 and n % c == 1) or ((ac_r == 0 and n % c == 2) or (ac_r == 2 and n % c == 2)) :
    n_c = n // c + 1
else:
    n_c = n // c
    
if (ad_r == 0 and n % d == 1) or ((ad_r == 0 and n % d == 2) or (ad_r == 2 and n % d == 2)):
    n_d = n // d + 1
else:
    n_d = n // d
    
if (acd_r == 0 and n % (c*d) == 1) or ((acd_r == 0 and n % (c*d) == 2) or (acd_r == 2 and n % (c*d) == 2)):
    n_cd = n // lcm + 1
else:
    n_cd = n // lcm
    
print(n - (n_c + n_d - n_cd)) 
print(ac_r, ad_r, acd_r, n)

Submission status: Runtime Error

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

ac_r = a % c
ad_r = a % d
acd_r = a % (c*d)

if (ac_r == 0 and n % c == 1) or ((ac_r == 0 and n % c == 2) or (ac_r == 2 and n % c == 2)) :
    n_c = (b - a + 1) // c + 1
else:
    n_c = (b - a + 1) // c
    
if (ad_r == 0 and n % d == 1) or ((ad_r == 0 and n % d == 2) or (ad_r == 2 and n % d == 2)):
    n_d = (b - a + 1) // d + 1
else:
    n_d = (b - a + 1) // d
    
if (acd_r == 0 and n % (c*d) == 1) or ((acd_r == 0 and n % (c*d) == 2) or (acd_r == 2 and n % (c*d) == 2)):
    n_cd = (b - a + 1) // (c*d) + 1
else:
    n_cd = (b - a + 1) // (c*d)
    
print((b - a + 1) - (n_c + n_d - n_cd))

Submission status: Runtime Error

Solution code:
from fraction import gcd
A, B, C, D = map(int, input().split())
BdivC, BdivD = B // C, B // D
AdivC, AdivD = A // C, A // D
GCD = gcd(C, D)
BdivCD, AdivCD = B // ((C * D) // GCD), A // ((C * D) // GCD)
N1 = BdivC + BdivD - BdivCD
N2 = AdivC + AdivD - AdivCD
ans = (B - A) - (N1 - N2)
if(A % C != 0): ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
A,B = map(int,input().split())
C,D = map(int,input().split())
count = 0
for i in range(A,B+1):
  if i%C != 0 and i%D != 0:
    count += 1
    i += 1
  else:
    i += 1
    break
print(count)

Submission status: Runtime Error

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


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


def search(n, i, j):
    l = lcm(i, j)
    return n - int(n / i) - int(n / j) + int(n / l)


print(search(b, c, d) - search(a - 1, c, d))

Submission status: Runtime Error

Solution code:
import math
def main(A,B,C,D):
    allAB = B - A + 1
    divC = B // C - (A-1) // C
    divD = B // D - (A-1) // D
    lcmCD = lcm(C,D)
    divCD = B // (lcmCD) - (A-1) // (lcmCD)
    count = allAB - divC - divD + divCD
    return count

def lcm(x, y):
    return (x*y) // math.gcd(x,y)
    
A,B,C,D = map(int, input().split())
print(main(A,B,C,D))

Submission status: Runtime Error

Solution code:
import math
def main(A,B,C,D):
    allAB = B - A + 1
    divC = B // C - (A-1) // C
    divD = B // D - (A-1) // D
    lcmCD = lcm(C,D)
    divCD = B // (lcmCD) - (A-1) // (lcmCD)
    count = allAB - divC - divD + divCD
    return count

def lcm(x, y):
    return (x*y) // math.gcd(x,y)
    
    
A,B,C,D = map(int, input().split())
print(main(A,B,C,D))

Submission status: Runtime Error

Solution code:
import fractions
from functools import reduce


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


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


A, B, C, D = map(int, input().split())
ans_b = B - (B // C) - (B // D) + (B // lcm_base(C, D))
ans_a = (A - 1) - ((A - 1) // C) - ((A - 1) // D) + ((A - 1) // lcm_(A - 1)ase(C, D))
print(ans_b - ans_a)

Submission status: Runtime Error

Solution code:
n = int(input())
ba_list = []
for i in range(n):
    ba_tmp = list(map(int, input().split()))
    ba_list.append([ba_tmp[1], [ba_tmp[0]])
ba_list.sort()
now_time = 0
for i in range(n):
    now_time += ba_list[i][1]
    if now_time > ba_list[i][0]:
        print('No')
        exit()
print('Yes')

Submission status: Runtime Error

Solution code:
import math

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

c_count = (b//c)-((a-1)//c)
d_count = (b//d)-((a-1)//d)

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

Submission status: Runtime Error

Solution code:
import math

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

c_count = (b//c)-((a-1)//c)
d_count = (b//d)-((a-1)//d)

cd = c*d // math.gcd(c,d)
cd_count = (b//cd) - ((a-1)//cd)
ans = (b+1-a)-c_count-d_count+cd_count

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

c_count = (b//c)-((a-1)//c)
d_count = (b//d)-((a-1)//d)

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

print((b+1-a)-c_count-d_count+cd_count)

Submission status: Runtime Error

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

c_count = (b//c)-((a-1)//c)
d_count = (b//d)-((a-1)//d)

import math

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

print((b+1-a)-c_count-d_count+cd_count)

Submission status: Runtime Error

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

c_count = (b//c)-((a-1)//c)
d_count = (b//d)-((a-1)//c)

import math

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

print((b+1-a)-c_count-d_count+cd_count)

Submission status: Runtime Error

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

c_count = (b//c)-((a-1)//c)
d_count = (b//d)-((a-1)//c)

import math

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

print(cd)
print(c_count)
print(d_count)
print(cd_count)

print((b+1-a)-c_count-d_count+cd_count)

Submission status: Runtime Error

Solution code:
a, b, c, d = [int(i) for i in input().split()]
total = b - a + 1


def pgcd(a, b):
    if b == 0:
        return a
    else:
        r = a % b
        return pgcd(b, r)


def ppcm(a, b):
    if (a == 0) or (b == 0):
        return 0
    else:
        return (a * b) // pgcd(a, b)


def occur(a, b, c):
    r = b - a + 1
    res = r // c
    first = a if not a % c else a + c - a % c
    if a + a % c >= fir st:
        res += 1
    return res


p = ppcm(c, d)
total -= occur(a, b, c)
total -= occur(a, b, d)
total += occur(a, b, p)

print(total)

Submission status: Runtime Error

Solution code:
#python3
from numpy import lcm
def main():
    a, b, c, d = map(int, input().split())
    p = b - ((b//c + b//d) - b//lcm(c, d))
    q = (a-1) - (((a-1)//c + (a-1)//d) - (a-1)//lcm(c, d))
    print(p-q)
main()

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
def calc(n,x,y):
    cnt = n // x
    cnt += n//y
    lcm = x*y//math.gcd(x,y)
    cnt -= int(n//lcm)
    return n - cnt

print(calc(b,c,d)-calc(a-1,c,d))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
def calc(n,x,y):
    cnt = n // x
    cnt += n//y
    lcm = x*y//math.gcd(x,y)
    cnt -= n//lcm
    return n - cnt

print(calc(b,c,d)-calc(a-1,c,d))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
ccnt=(b//c)-math.ceil(a//c)
dcnt=(b//d)-math.ceil(a//d)
e=int(c*d/math.gcd(c,d))
ecnt=(b//e)-math.ceil(a//e)
ans=(b-a+1)-(ccnt+dcnt-ecnt)
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

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

n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
#print("n_c: ", n_c)
#print("n_d: ", n_d)

cd = c*d//np.gcd(c,d)
n_cd = b//cd - (a-1)//cd
#print("n_cd: ", n_cd)

n_ab = b+1-a
#print("n_ab: ", n_ab)

print(n_ab-(n_c+n_d)+n_cd)

Submission status: Runtime Error

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

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

n_c = b//c - a//c
n_d = b//d - a//d
#print("n_c: ", n_c)
#print("n_d: ", n_d)

cd = c*d//math.gcd(c,d)
n_cd = b//cd - a//cd
#print("n_cd: ", n_cd)

n_ab = b+1-a
#print("n_ab: ", n_ab)

print(n_ab-(n_c+n_d)+n_cd)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
def gcd(a,b):
    if b>a:
        b,a=a,b
    if b==0:
        return a
    else:
        return gcd(b,a%b)


def warikiri(n,c,d):
    koubai=(c*d)//gcd(c,d)
    return n-n//d-n//c+n//koubai)
print(warikiri(b,c,d)-warikiri(a-1,c,d))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math


def func(a, b, div):
    if (a/div).is_integer(): c_1 = int(a/div)
    else: c_1 = a // div + 1
    c_2 = b // div
    return int(c_2 - c_1 + 1)


a, b, c, d = (int(x) for x in input().split())
print(int((b - a + 1) - func(a, b, c) - func(a, b, d) + func(a, b, c*d//math.gcd(c, d))))

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = (int(x) for x in input().split())
def func(div):
    if (a/div).is_integer(): c_1 = int(a/div)
    else: c_1 = a // div + 1
    c_2 = b // div
    return int(c_2 - c_1 + 1)
print(int((b - a + 1) - func(c) - func(d) + func(c*d//math.gcd(c, d))))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
import math

def main():
    A, B, C, D = list(map(int, input().split()))
    lcm = C * D / math.gcd(C, D)

    Ac = int(A/C)
    if A % C == 0:
        Ac-=1

    Bc = int(B/C)
    cnum = Bc - Ac

    Ad = int(A/D)
    if A % D == 0:
        Ad-=1

    Bd = int(B/D)
    dnum =Bd - Ad

    Alcm = int(A/lcm)
    if A % lcm == 0:
        Alcm-=1

    Blcm = int(B/lcm)
    lcmnum = Blcm - Alcm

    print(B - A + 1 - (cnum + dnum - lcmnum))

main()

Submission status: Runtime Error

Solution code:
data = list(map(int, input().split()))
A = data[0]
B = data[1]
C = data[2]
D = data[3]
def antinum(t,bo):
    n = 0
    kaesi = []
    while n <= len(t) - 1:
        if t[n] % bo != 0:
            kaesi += [t[n]]
        if n == len(t) - 1:
            return kaesi
        n += 1
src = []
sa = A
while sa <= B:
    src += [sa]
    sa += 1
nexts = antinum(src,C)
print(len(antinum(nexts,D)))

Submission status: Runtime Error

Solution code:
import math

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

Submission status: Runtime Error

Solution code:
from math import gcd
A, B, C, D = list(map(int, input().split()))
num_B_C = B // C
num_B_D = B // D
lcm_C_D = int(C * D / gcd(C, D))
num_B = B - (num_B_C + num_B_D) + B // lcm_C_D

num_A_C = (A-1) // C
num_A_D = (A-1) // D
num_A = (A-1) - (num_A_C + num_A_D) + (A-1) // lcm_C_D

ans = num_B - num_A
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

ac1,ac2 = a//c,a%c
ad1,ad2 = a//d,a%d
bc1,bc2 = b//c,b%c
bd1,bd2 = b//d,b%d
acd1,acd2 = a//cd,a%cd
bcd1,bcd2 = b//cd,b%cd

if ac2 == 0:
    a_ = bc1-ac1+1
else:
    a_ = bc1-ac1

if ad2 == 0:
    b_ = bd1-ad1+1
else:
    b_ = bd1-ad1

if acd2 == 0:
    c_ = bcd1-acd1+1
else:
    c_ = bcd1-acd1

print(b-a+1-(a_+b_-c_))

Submission status: Runtime Error

Solution code:
import math


def func(n, c, d):
    x = n // c
    y = n // d
    z = n // (c * d // math.gcd(c, d))

    return n - x - y + z


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

print(func(b, c, d) - func(a - 1, 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())
count = 0
i = b//c - a//c 
if(a%c == 0):
  i += 1
j = b//d - a//d
if(a%d == 0):
  j += 1
k = b//lcm(c,d) - a//lcm(c,d)

print(b-a+1-(i+j-k))

Submission status: Runtime Error

Solution code:
a, b, c, d = [int(i) for i in input().split()]
n = {i for i in range(a, b+1) if i % c != 0 and i % d != 0}4 9 2 3
ans = len(n)
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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


def f(n):
    x = n//c
    x += n//d
    lcm = c*d//gcd(c, d)
    x -= n//lcm
    return n-x


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

Submission status: Runtime Error

Solution code:
from math import gcd

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


def f(n):
    x = n//c
    x += n//d
    lcm = c*d/gcd(c, d)
    x -= n//lcm
    return n-x


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

Submission status: Runtime Error

Solution code:
from math import gcd

A, B, C, D = map(int, open(0).read().split())
k = (C*D)//gcd(C,D)

def calc(x):
    q = (x//C)+(x//D)-(x//k)
    return x-q

print(calc(B) - calc(A-1))

Submission status: Runtime Error

Solution code:
import math

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


# upper 以下で div で割り切れるものの個数
def num_divisor(upper, div):
    return upper // div


# upper 以下で c でも d でも割り切れないものの個数
def num_divisor_c_d(upper, c, d):
    gcd_cd = c * d // math.gcd(c, d)

    n1 = num_divisor(upper, c)
    n2 = num_divisor(upper, d)
    n12 = num_divisor(upper, gcd_cd)

    return upper - (n1 + n2 - n12)


ans = num_divisor_c_d(b, c, d) - num_divisor_c_d(a - 1, c, d)

print(ans)

Submission status: Runtime Error

Solution code:
#from fractions import gcd
import math
A,B,C,D = map(int,input().split())
num_gcd = C*D//math.gcd(C,D)
ans_B = 0 - B//C - B//D + B//num_gcd
ans_A = 0 - (A-1)//C - (A-1)//D + (A-1)//num_gcd
ans = B - A + 1 + ans_B - ans_A
print(ans)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int, input().split())
res = 0
lcm = c*d // math.gcd(c,d)
divisible = (b//c) - ((a-1)//c) + (b//d) - ((a-1)//d) - (b//lcm) - ((a-1)//lcm)
res = b-a+1 - divisible
print(res)

Submission status: Runtime Error

Solution code:
import sys
import math
import fractions
def input(): return sys.stdin.readline().rstrip()

def main():
    a, b, c, d = map(int, input().split())
    def count_ab(n):
        return math.floor(b / n) - math.ceil(a / n) + 1
    c_cnt = count_ab(c)
    d_cnt = count_ab(d)
    cd_cnt = count_ab(c * d // fractions.gcd(c, d))

    print(b - a - c_c - d_c + cd_c + 1)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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())
lcm = lcm(C,D)
E = int((A-1)/C)
F = int((A-1)/D)
G = int((A-1)/lcm)
H = int(B/C)
I = int(B/D)
J = int(B/lcm)

count = (B-A+1)-((H-E)+(I-F)-(J-G))

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())
lcm = lcm(C,D)
E = (A-1)//C
F = (A-1)//D
G = (A-1)//lcm
H = B//C
I = B//D
J = B//lcm

count = (B-A+1)-((H-E)+(I-F)-(J-G))

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

lcm_cd = lcm(c,d)

min_a_c = (a-1)//c
min_a_d = (a-1)//d
min_a_lcm = (a-1)//lcm_cd
max_b_c = b//c
max_b_d = b//d
max_b_lcm = b//lcm_cd

ans=(b-a+1)-((max_b_c-min_a_c)+(max_b_d-min_a_d)-(max_b_lcm-min_a_lcm))


print(ans)

Submission status: Runtime Error

Solution code:
#ABC_131_C
import math

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


def f(A,B,X):
    if A%X==0 or B%X==0:
        X_num=1+(B-A)//X
    else:
        X_num=(B-A)//X
    return X_num


C_num=f(A,B,C)
D_num=f(A,B,D)

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

CD_num=f(A,B,CD_m)

ans=(B-A+1)-C_num-D_num+CD_num
print(ans)

Submission status: Runtime Error

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

print(int(x-y))

Submission status: Runtime Error

Solution code:
#ABC-131-C
import math
A, B, C, D = map(int, input().split())
lcm = C * D // math.gcd(C, D)
#1~A-1までの数字でCでもDでも割り切れないものの個数
A_divided_C = (A-1) // C
A_divided_D = (A-1) // D
A_divided_CD = (A-1) // (lcm)
one_to_A = (A-1) - A_divided_C - A_divided_D + A_divided_CD

#1~Bまでの数字でCでもDでも割り切れないものの個数
B_divided_C = B // C
B_divided_D = B // D
B_divided_CD = B // (lcm)
one_to_B = B - B_divided_C - B_divided_D + B_divided_CD

ans = one_to_B - one_to_A
print(ans)

Submission status: Runtime Error

Solution code:

import fractions
a,b,c,d=map(int,input().split())
x1=b//c-(a-1)//c #ｃの割れるやつ
x2=b//d-(a-1)//d　#ｄの割れるやつ
sks=c * d // fractions.gcd(c,d)#最小公倍数　普通ならmathメソッドにある
x3=b//sks-(a-1)//sks#ｃ＊ｄの割れるやつ
ans=b-a+1-(x1+x2-x3)
print (ans)

Submission status: Runtime Error

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

x1=b//c-a//c
x2=b//d-a//d
sks=c * d // math.gcd(c,d)
x3=b//sks-a//sks
ans=(x1+x2)-x3
print (ans)