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

Solution (Python):
def calc(a, b):
    x = max(a, b)
    y = min(a, b)
    while True:
        c = x % y
        if c == 0:
            break
        x = y
        y = c
    return y

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

E = int(C * D / calc(C, D))
l = int(B - B // C - B // D + B // E)
m = int((A-1) - (A-1) // C - (A-1) // D + (A-1) // E)

print(l-m)

Solution (Python):
from math import gcd 

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

Bc = B // C
Bd = B // D

G = gcd(C,D)
L = int(C*D/G)

Bl = B//L

RangeB = B-(Bc+Bd-Bl)

Ac = (A-1) // C
Ad = (A-1) // D
Al = (A-1) // L

RangeA = (A-1)-(Ac+Ad-Al)

print(RangeB-RangeA)

Solution (Python):
import math

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


C_multiple = B // C - A // C
D_multiple = B // D - A // D 

if A % C == 0:
    C_multiple += 1
if A % D == 0:
    D_multiple += 1
        

CD_gcd = C * D // math.gcd(C,D) 
CD_multiple = B // CD_gcd - A// CD_gcd 
if A % CD_gcd == 0:
    CD_multiple += 1



ans = ( B - A + 1 ) - (C_multiple + D_multiple - CD_multiple)
print(int(ans))

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

def div(n,p):
  return n//p

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

ans=b-a+1
ans-=(div(b,c)-div(a-1,c))
ans-=(div(b,d)-div(a-1,d))
e=lcm(c,d)
ans+=(div(b,e)-div(a-1,e))
print(ans)

Solution (Python):
import sys
import math

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


maru1 = B // C
maru2 = (A-1) // C

maru3 = B // D
maru4 = (A-1) // D

maru5 = B // lcm(C,D)
maru6 = (A-1) // lcm(C,D)

ans_tmp = ((maru1-maru2)+(maru3-maru4)) - (maru5-maru6)
ans = (B-A+1) - ans_tmp

print(ans)

Solution (Python):
import math

def delete_head_zeros(n):
	n = str(n)
	l = len(n)
	if "." in n:
		l = n.find(".")
	head_zeros = 0
	for i in range(l - 1):
		if n[i] == "0":
			head_zeros += 1
		else:
			break

	return n[head_zeros:]



def bigint_compare(a, b):
	a = delete_head_zeros(a)
	b = delete_head_zeros(b)
	if len(a) > len(b):
		return 1
	elif len(a) < len(b):
		return -1
	else:
		if a > b:
			return 1
		elif a < b:
			return -1
		else:
			return 0



def bigint_plus(a, b):
	a = str(a)
	b = str(b)

	d = max([len(a), len(b)])
	a = '0' * (d - len(a)) + a
	b = '0' * (d - len(b)) + b

	ans = ""
	carry = 0
	for i in range(d):
		s = int(a[-i-1]) + int(b[-i-1]) + carry
		carry = s // 10
		ans = str(s % 10) + ans
	else:
		if carry:
			ans = str(carry) + ans

	return ans



def bigint_minus(a, b): 
	a = str(a)
	b = str(b)
	M = []
	m = []
	sign = ""

	if len(a) > len(b) or (len(a) == len(b) and a >= b):
		[M, m] = [a, b]
	else:
		[M, m] = [b, a]
		sign = "-"
	m = '0' * (len(M) - len(m)) + m

	ans = ""
	borrow = 0
	for i in range(len(M)):
		s = int(M[-i-1]) - int(m[-i-1]) - borrow
		if s < 0:
			borrow = 1
			s += 10
		else:
			borrow = 0
		ans = str(s) + ans

	return sign + delete_head_zeros(ans)



def bigint_multiply(a, b):
	a = str(a)
	b = str(b)

	md = []
	carry = 0
	for j in range(len(b)):
		mj = ""
		for i in range(len(a)):
			m = int(a[-i-1]) * int(b[-j-1]) + carry
			carry = m // 10
			mj = str(m % 10) + mj
		else:
			if carry:
				mj = str(carry) + mj
		md.append(mj)

	ans = 0
	for k in range(len(md)):
		ans = bigint_plus(md[k] + "0" * k, ans)

	return ans




def bigint_divide(a, b, d = 0):
	a = str(a)
	b = str(b)
	d = int(d)
	if d < 0:
		d = 0

	ans = ""
	r = ""
	for i in range(len(a) + d):
		q = 0
		if i < len(a):
			r += a[i]
		elif i == len(a):
			ans += "."
			r += "0"
		else:
			r += "0"

		if bigint_compare(r, b) == -1:
			ans += str(q)
		else:
			while bigint_compare(r, b) >= 0:
				r = bigint_minus(r, b)
				q += 1
			ans += str(q)

	return delete_head_zeros(ans)

A, B, C, D = [n for n in input().split(" ")]
lcm = bigint_divide(bigint_multiply(C, D), math.gcd(int(C), int(D)))
right = B
left = bigint_minus(A, 1)
allcnt = bigint_minus(right, left)
def mulN(x):
  return bigint_minus(bigint_divide(right, x), bigint_divide(left, x))

print(bigint_minus(bigint_plus(allcnt, mulN(lcm)), bigint_plus(mulN(C), mulN(D))))

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    from functools import reduce
    def lcm_base(n1,n2):
        return (n1*n2)//math.gcd(n1,n2)
    def lcm(*numbers):
        return reduce(lcm_base, numbers)
    a,b,c,d = LI()
    cd = lcm(c,d)
    lst = [c,d,cd]
    ans_lst = []
    for ex in lst:
        before = a if a % ex == 0 else a+ex-(a%ex)
        after = b - (b%ex)
        
        if before > after:
            ans_lst.append(0)
        else:
            bnum = before//ex
            anum = after//ex
            num = anum - bnum +1
            ans_lst.append(num)
            
    ans =(b-a +1) - (ans_lst[0] + ans_lst[1] - ans_lst[2])
    
    print(ans)

main()

Solution (Python):
def gcd(a,b):
	return max(a,b) if min(a,b)==0 else gcd(min(a,b),max(a,b)%min(a,b))
a,b,c,d=map(int,input().split())
l=c*d//gcd(c,d)
cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
ll=b//l-(a-1)//l
print(b-a+1-(cc+dd-ll))

Solution (Python):
import math

def main():
    A, B, C, D = map(int, input().split())
    lcm = C * D // math.gcd(C, D)
    C_div = B // C - (A - 1) // C
    D_div = B // D - (A - 1) // D
    C_D_div = B // lcm - (A - 1) //lcm
    print(B - A + 1 - C_div - D_div + C_D_div)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C, D = MAP()

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

E = B - (B//C + B//D - B//(CD_lcm))
F = A - (A//C + A//D - A//(CD_lcm))

ans = E - F

if A % C != 0 and A % D != 0:
    ans += 1

print(ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C, D = MAP()

def many_lcm(l):
    tmp = l[0]
    for i in range(1, len(l)):
        tmp = tmp * l[i]//gcd(tmp, l[i])
    return tmp





total = B - (A - 1)

A = A - 1
lc = many_lcm([C, D])


a = A - (A // C + A // D - A // (lc))
b = B - (B // C + B // D - B // (lc))
print(b - a)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    A, B, C, D = MAP()

    X = B // C - (A - 1) // C
    Y = B // D - (A - 1) // D
    g = (C * D) // gcd(C, D)
    Z = B // g - (A - 1) // g

    print(B - A + 1 - X - Y + Z)


if __name__ == '__main__':
    main()

Solution (Python):
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)

lcm_=lcm(C,D)
answer=B-A+1-(B//C-A//C)-(B//D-A//D)+(B//lcm_-A//lcm_)
if A%C==0:
    answer-=1
if A%D==0:
    answer-=1
if answer<=-1:
    print(0)
else:
    if A%C==0 and A%D==0:
        print(answer+1)
    else:
        print(answer)

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7



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

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

c = B // C - (A-1) // C
d = B // D - (A-1) // D
e = B // lcm_base(C, D) - (A-1) // lcm_base(C, D)

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

Solution (Python):
import math
a, b, c, d = map(int, input().split())
e = c * d //math.gcd(c, d)
ans = b - a + 1
cnt_of_c = (b // c) - ((a - 1) // c)
cnt_of_d = (b // d) - ((a - 1) // d)
cnt_of_e = (b // e) - ((a - 1) // e)
ans -= cnt_of_c + cnt_of_d - cnt_of_e

print(ans)

Solution (Python):
import math
A, B, C, D = map(int, input().split())
CD = C * D // math.gcd(C, D)
ab = B - A + 1
c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
cd = B // (CD) - (A - 1) // (CD)

print(ab - (c + d - cd))

Solution (Python):
import math





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


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

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


if __name__ == "__main__":
    main()

Solution (Python):
a,b,c,d=map(int,input().split())
from math import gcd
ans=0
def main(n):
    e=n//c+n//d-n//((c*d)//gcd(c,d))
    return n-e

print(main(b)-main(a-1))

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Solution (Python):
import numpy
a,b,c,d= list(map(int, input().strip().split()))
e=numpy.lcm(c,d)
def kosuu(x):
    return(b//x-(a-1)//x)
print(b-a+1-kosuu(c)-kosuu(d)+kosuu(e))

Solution (Python):
a,b,c,d=map(int,input().split())
from math import gcd
ans=0
def main(n):
    e=n//c+n//d-n//((c*d)//gcd(c,d))
    return n-e

print(main(b)-main(a-1))

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

Solution (Python):
import math

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

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

ans = b-(a-1)

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

ca = (a-1)//c
cb = b//c
da = (a-1)//d
db = b//d
cda = (a-1)//lcm(c,d)
cdb = b//lcm(c,d)
ans -= (cb+db-cdb) - (ca+da-cda)
print(ans)

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

def LCM(S, T):
    return (S*T)//math.gcd(S, T)

def f(N, S, T):
    return N- N//S - N//T + N//LCM(S, T)
    
    
print(f(B, C, D)-f(A-1, C, D))

Solution (Python):
from math import *

A,B,C,D=map(int,input().split())
mc=B//C-(A-1)//C
md=B//D-(A-1)//D
cd=(C*D)//gcd(C,D)
mcd=B//cd-(A-1)//cd
print(B-A+1-mc-md+mcd)

Solution (Python):
import math

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


E = C*D//math.gcd(C,D)
def num_mult(fro,to,mult):
    goal = to//mult
    if fro % mult == 0:
        start = fro // mult
    else:
        start = fro // mult + 1
    
    return goal - start + 1

ans = B-A+1

ans -= num_mult(A,B,C)

ans -= num_mult(A,B,D)

ans += num_mult(A,B,E)

print(ans)

Solution (Python):
import math

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

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

def num(i):
  ans = b//i - a//i
  if a % i == 0:
    ans +=1
  return ans

lcm_num = num(lcm)

cd_num  = num(c) + num(d)

num = cd_num - lcm_num

print(b-a+1-num)

Solution (Python):
import math
def yaku(n,p,q):
    lcm = (p*q)//math.gcd(p,q)
    return (n//p + n//q - n//lcm)
a,b,c,d = map(int,input().split())
print((b-a+1)-((yaku(b,c,d)) - yaku(a-1,c,d)))

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

lcm = C*D // gcd(C,D)
a = (A-1)//C + (A-1)//D - (A-1)//lcm
b = B//C + B//D - B//lcm

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

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

lcm = C*D // gcd(C,D)
a = (A-1)//C + (A-1)//D - (A-1)//lcm
b = B//C + B//D - B//lcm

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

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

Solution (Python):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    a,b,c,d=MI()
    cc=b//c - (a-1)//c
    dd=b//d - (a-1)//d
    
    import math
    g=(c*d)//math.gcd(c,d)
    gg=b//g - (a-1)//g
    
    print(b-a+1 -cc-dd+gg)

main()

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

a,b,c,d=map(int,input().split())
e=b//c-(a-1)//c
f=b//d-(a-1)//d

g=b//lcm(c,d)-(a-1)//lcm(c,d)
ans=e+f-g

print(b-a+1-ans)

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

Solution (Python):
import math
a,b,c,d=list(map(int,input().split()))
a-=1
def calculation(x,c,d):
	x=x-(x//c)-(x//d)+(x//((c*d)//math.gcd(c,d)))
	return x
	
print(calculation(b,c,d)-calculation(a,c,d))

Solution (Python):
from math import gcd
a,b,c,d=list(map(int,input().split()))
a-=1
def calculation(x,c,d):
	x=x-(x//c)-(x//d)+(x//((c*d)//gcd(c,d)))
	return x
	
print(calculation(b,c,d)-calculation(a,c,d))

Solution (Python):
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)

cnt_C=B//C-(A-1)//C
cnt_D=B//D-(A-1)//D

lcm_CD=lcm(C,D)
cnt_CD=B//lcm_CD-(A-1)//lcm_CD

ans=(B-A+1)-cnt_C-cnt_D+cnt_CD
print(ans)

Solution (Python):
import math

A,B,C,D = map(int, input().split())
E = C*D // math.gcd(C, D)
count =0
n = (A-1)//C
m = B//C
o = (A-1)//D
p= B//D
q= (A-1)//E
r= B//E
print((B-A+1) - ((m-n)+(p-o)-(r-q)))

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

l = C*D//fractions.gcd(C,D)
x = B-(B//C+B//D-B//l)
y = (A-1)-((A-1)//C+(A-1)//D-(A-1)//l)
print(x-y)

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

def calc_div_num(a,b,x):
  return b//x - (a-1)//x

num_c = b//c - (a-1)//c
num_d = b//d - (a-1)//d

import math
lcd = int(c * d / math.gcd(c,d))
num_lcd = b//lcd - (a-1)//lcd

result = b-a+1 - (num_c+num_d-num_lcd)
print(result)

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

def calc_div_num(a,b,x):
  return b//x - (a-1)//x

num_c = calc_div_num(a, b, c)
num_d = calc_div_num(a, b, d)

import numpy as np
import math

lcd = c*d/math.gcd(c,d)
num_lcd = calc_div_num(a, b, int(lcd))

result = b-a+1 - (num_c+num_d-num_lcd)
print(result)

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

def calc_div_num(a,b,x):
  return b//x - (a-1)//x

num_c = calc_div_num(a, b, c)
num_d = calc_div_num(a, b, d)

import numpy as np
lcd = np.lcm(c, d)
num_lcd = calc_div_num(a, b, lcd)

result = b-a+1 - (num_c+num_d-num_lcd)
print(result)

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

Solution (Python):








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
















import math

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

def func(val, x, y):
    return val-val//x-val//y+val//lcm(x,y)

ans = (func(b,c,d)-func(a-1,c,d))
print(ans)

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


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


print(fn(b)-fn(a-1))

Solution (Python):
import sys
import math

inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

a, b, c, d = inintm()

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

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

Solution (Python):
A, B, C, D = list(map(int, input().split()))
c1 = (A - 1) // C
c2 = B // C
d1 = (A - 1) // D
d2 = B //D
import math
E = (C * D) // math.gcd(C, D)
e1 = (A - 1) // E
e2 = B //E

print(B - A + 1 -(c2 - c1 + d2 - d1 - (e2 - e1)))

Solution (Python):
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    a,b,c,d = map(int, input().split())
    x = b//c - (a-1)//c
    y = b//d - (a-1)//d
    e = c*d//gcd(c,d)
    z = b//e - (a-1)//e
    ans = b-a+1 -x-y +z
    print(ans)

if __name__=="__main__":
    main()

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


A,B,C,D = LI()

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



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

ans = B-(A-1)+1 - tmp
print(ans)

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

import math

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

cnt_a=a-a//c-a//d+a//lcm(c,d)
cnt_b=b-b//c-b//d+b//lcm(c,d)

if a%c==0 or a%d==0:
  print(cnt_b-cnt_a)
else:
  print(cnt_b-cnt_a+1)

Solution (Python):
import math

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

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

def cnt(x):
  return b//x - a//x + int(a%x==0)

print(b-a+1 - cnt(c) - cnt(d) + cnt(l))

Solution (Python):
from math import gcd


def count_indivs(N):
    return N - (N // C + N // D - N // L)


A, B, C, D = map(int, input().split())
L = C * D // gcd(C, D)
print(count_indivs(B) - count_indivs(A - 1))

Solution (Python):
from math import gcd

a, b, c, d = map(int, input().split())
e = c // gcd(c, d) * d
cnt = lambda n: n // c + n // d - n // e
print(b - a + 1 - cnt(b) + cnt(a - 1))

Solution (Python):
def cnt(n):
    return n // c + n // d - n // e


from math import gcd

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

Solution (Python):
A, B, C, D = map(int,input().split())
c = B//C-A//C + (A%C == 0)
d = B//D-A//D + (A%D == 0)
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)
E = lcm(C,D)
e = B//E-A//E + (A%E == 0)
print(B-A+1-c-d+e)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations,accumulate, product 

from collections import deque,defaultdict,Counter
import decimal
import re












import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
a,b,c,d = readInts()
ad = a-1
cdg = gcd(c,d)
cdl = c*d//cdg
b = b - b//c - b//d + b//cdl
ad = ad - ad//c - ad//d + ad//cdl
print(b-ad)

Solution (Python):
import math
A, B, C, D = map(int, input().split())
lcm = (C * D) // math.gcd(C, D)
waruC = B//C-(A-1)//C
waruD = B//D-(A-1)//D
waruCD = B//lcm-(A-1)//lcm
ans = B-A+1-(waruC+waruD-waruCD)
print(ans)

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

a = a - 1


def gcd(x: int, y: int) -> int:
    if x < y:
        x, y = y, x
    while y > 0:
        r = x % y
        x, y = y, r
    return x


cd = (c * d) // gcd(c, d)

a_c = a // c
b_c = b // c
a_d = a // d
b_d = b // d
a_cd = a // cd
b_cd = b // cd

res = b - (b_c + b_d - b_cd) - (a - (a_c + a_d - a_cd))
print(res)

Solution (Python):
a, b, c, d = map(int, input().split())
s = b//c-(a-1)//c
t = b//d-(a-1)//d


import math
from functools import reduce
def lcm_base(x, y):
  
  return (x * y) // math.gcd(x, y)

l = lcm_base(c, d)

r = b//l-(a-1)//l



ans = b-a+1-(s+t-r)
print(ans)

Solution (Python):
from math import gcd
def calc(a,b,n):
  return b//n-(a-1)//n
def solve():
  A, B, C, D = map(int, input().split())
  ans = B-A+1-calc(A,B,C)-calc(A,B,D)+calc(A,B,C*D//gcd(C,D))
  return ans
print(solve())

Solution (Python):
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
A,B,C,D = map(int,input().split())
c1 = B//C-(A-1)//C
d1 = B//D-(A-1)//D
E = (C//gcd(C,D))*D
e1 = B//E-(A-1)//E
print(B-A+1-c1-d1+e1)

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

C = b//c - (a-1)//c
D = b//d - (a-1)//d
x = c*d//math.gcd(c,d)
CD = b//x - (a-1)//x

print((b-a+1) - (C+D-CD))

Solution (Python):
from math import gcd

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

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

a_cnt = 0
a_cnt = (b//c) - ((a-1)//c)
b_cnt = (b//d) - ((a-1)//d)

lcmab = lcm(c,d)
ab_cnt = (b//lcmab) - ((a-1)//lcmab)

ans = (b-a+1) - a_cnt -b_cnt + ab_cnt
print(ans)

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

from math import gcd
def cnt(n):
    lcm = c//gcd(c,d)*d
    return n - n//c - n//d + n//lcm
print(cnt(b)-cnt(a-1))

Solution (Python):
import math
def lcm(x,y):
    return (x*y)//math.gcd(x,y)
a,b,c,d=map(int,input().split())
bc=b//c
bd=b//d
bcd=b//lcm(c,d)
x=b-(bc+bd-bcd)
a=a-1
ac=a//c
ad=a//d
acd=a//lcm(c,d)
y=a-(ac+ad-acd)
print(x-y)

Solution (Python):
A,B,C,D=map(int,input().split())
def f(x):
  return B//x-(A-1)//x
import math
E=int(C*D/math.gcd(C,D))
print(B-A+1-f(C)-f(D)+f(E))

Solution (Python):
import math
A,B,C,D=map(int,input().split())
def X(x):
    c=x//C
    d=x//D
    l=C*D//math.gcd(C,D)
    return x-c-d+(x//l)
print(X(B)-X(A-1))

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

a_div_c = (a-1) // c
a_div_d = (a-1) // d
a_div_cd = (a-1) // (c * d // math.gcd(c, d))
b_div_c = b // c
b_div_d = b // d
b_div_cd = b // (c * d // math.gcd(c, d))

y = b - (b_div_c + b_div_d - b_div_cd)
x = (a - 1) - (a_div_c + a_div_d - a_div_cd)

print(y-x)

Solution (Python):
import math
a,b,c,d=map(int,input().split())
lcm_cd=c*d//math.gcd(c,d)
c_cnt=b//c-(a-1)//c
d_cnt=b//d-(a-1)//d
cd_cnt=b//lcm_cd-(a-1)//lcm_cd
print(b-a+1-c_cnt-d_cnt+cd_cnt)

Solution (Python):
import fractions
A, B, C, D = map(int, input().split())
n_C = B // C - (A-1) //C
n_D = B // D - (A-1) //D
n = (C * D) // fractions.gcd(C, D)
n_C_D = B // n - (A-1)// n
print(B-A-n_C-n_D+n_C_D+1)

Solution (Python):
import math

a, b, c, d = map(int, input().split())
cd = (c * d) // math.gcd(c, d)
u = b//c + b//d - b//cd
l = (a-1)//c + (a-1)//d - (a-1)//cd

print(b - a + 1 - u + l)

Solution (Python):
import math

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

u = b//c + b//d - b//l
l = (a-1)//c + (a-1)//d - (a-1)//l

print(b - a + 1 - u + l)

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

divc = b//c-(a-1)//c
divd = b//d-(a-1)//d
import math
l = c*d//math.gcd(c,d)
divl = b//l-(a-1)//l
print(b-a+1-divc-divd+divl)

Solution (Python):
from math import gcd
lcm = lambda x,y: (x*y)//gcd(x,y)
A,B,C,D = [int(i) for i in input().split()]
print(B - A + 1 - (B//C - (A-1)//C) - (B//D - (A-1)//D) + (B//lcm(C,D) - (A-1)//lcm(C,D)))

Solution (Python):
import math
def lcm(x, y):return (x * y) // math.gcd(x, y)
a,b,c,d=map(int,input().split())

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

Solution (Python):
import math

a, b, c, d = map(int, input().split())
total = b - a + 1
c_cnt = b // c - (a-1) // c
d_cnt = b // d - (a-1) // d
common_div = (c * d) // math.gcd(c, d)
common_cnt = b // common_div - (a-1) // common_div
total = total - c_cnt - d_cnt + common_cnt
print(total)

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

def cnt(x):
    return B//x - A//x + (A%x==0)

from math import gcd

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

print((B-A+1)-cnt(C)-cnt(D)+cnt(l))

Solution (Python):
def binary_search_int(ok, ng, test, p):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if test(mid, p):
            ok = mid
        else:
            ng = mid
    return ok

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

from math import gcd

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

def test1(x, p):
    return x*p<=B
b = [binary_search_int(0,10**18+1,test1, x) for x in [C, D, l]]

def test2(x, p):
    return x*p>=A

a = [binary_search_int(10**18+1, 0,test2, x) for x in [C, D, l]]

res = [x-y+1 if (x!=0 and y!=10**18+1) else 0 for x, y in zip(b, a)]


print((B-A+1)-res[0]-res[1]+res[2])

Solution (Python):
import math
from decimal import Decimal
a, b, c, d = list(map(int, input().split()))

cnt = 0
numc = b//c - math.ceil(Decimal(a)/Decimal(c)) + 1
numd = b//d - math.ceil(Decimal(a)/Decimal(d)) + 1

def gcd(a, b):
    if a == 0:
        return b
    elif b == 0:
        return a
    else:
        return gcd(b, a%b)

cd = (c*d) // gcd(c, d)
numcd = b//cd - math.ceil(Decimal(a)/Decimal(cd)) + 1

cnt = b - a + 1 - numc - numd + numcd

print(cnt)

Solution (Python):
import math
a,b,c,d=map(int,input().split())
count=b-a+1
acou=((a-1)//c)+((a-1)//d)-int(((a-1)//(c*d//math.gcd(c,d))))
bcou=(b//c)+(b//d)-int((b//(c*d//math.gcd(c,d))))
print(count-(bcou-acou))

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

A=a-1
l=c*d//math.gcd(c,d)
acou=(A//c)+(A//d)-int((A//l))
bcou=(b//c)+(b//d)-int((b//l))

print(count-(bcou-acou))

Solution (Python):
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
    
A, B, C, D = list(map(int,input().rstrip().split()))
lcm = int(C/gcd(C,D)*D)
ans = B-A+1
ans -= B//C-(A-1)//C
ans -= B//D-(A-1)//D
ans += B//lcm-(A-1)//lcm
print(ans)

Solution (Python):
import fractions

a,b,c,d=map(int,open(0).read().split())

e=c*d//fractions.gcd(c,d)

nc=b//c-(a-1)//c
nd=b//d-(a-1)//d
ne=b//e-(a-1)//e

print(b-a+1-nc-nd+ne)

Solution (Python):




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

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

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

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

Solution (Python):
from math import gcd


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


a, b, c, d = map(int, input().split())
e = lcm(c, d)
num_e = b // e - (a - 1) // e
num_c = b // c - (a - 1) // c
num_d = b // d - (a - 1) // d
num_can_div = num_c + num_d - num_e

print((b - a) - num_can_div + 1)

Solution (Python):
import math

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

c = B//C - (A-1)//C
d = B//D - (A-1)//D
cd = B//lcm - (A-1)//lcm

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

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

Solution (Python):
import math
a,b,c,d=map(int,input().split())
mc = b//c-(a-1)//c
md = b//d-(a-1)//d
cd = (c*d)//math.gcd(c,d)
mcd = b//cd - (a-1)//cd

print(b-a+1 - mc-md+mcd)

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

num1=b//c
num2=b//d
num3=b//g
num4=(a-1)//c
num5=(a-1)//d
num6=(a-1)//g


print(b-a+1-(num1+num2-num3-num4-num5+num6))

Solution (Python):
import numpy as np
A,B,C,D = map(int,input().split())
E = np.lcm(C,D)
print(1+B-A-B//C+(A-1)//C-B//D+(A-1)//D+B//E-(A-1)//E)

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

x = (a - 1) - (a - 1) // c - (a - 1) // d + (a - 1) // lcm
y = b - b // c - b // d + b // lcm

print(y - x)

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

Solution (Python):
import math

A, B, C, D = [int(x) for x in input().split(" ")]
lcm_c_d = (C * D) // math.gcd(C, D)
num_c = (B // C) - (A - 1) // C
num_d = (B // D) - (A - 1) // D
num_cd = (B // lcm_c_d) - (A - 1) // lcm_c_d
print(B - A - num_c - num_d + num_cd + 1)

Solution (Python):
from math import gcd


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


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


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

Solution (Python):
import math

def getDivCount( a, b, x ):
    count=0
    if a!=0 :
        count+=b//x-(a-1)//x
    else:
        count+=b//x+1
    return count

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

count = b-a+1
count -= getDivCount(a,b,c)
count -= getDivCount(a,b,d)
count += getDivCount(a,b,c*d//math.gcd(c,d))
print(count)

Solution (Python):
import math
A, B, C, D = map(int, input().split())
cdiv = B // C - (A - 1) // C
ddiv = B // D - (A - 1) // D
lcm = (C * D) // math.gcd(C, D)
cddiv = B // lcm - (A - 1) // lcm
ans = (B - A + 1) - (cdiv + ddiv - cddiv)
print(ans)

Solution (Python):
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


A, B, C, D = list(map(int, input().split()))
Bc = B // C
Bd = B // D
Ac = (A - 1) // C
Ad = (A - 1) // D
lcm = C * D // gcd(C, D)
Blcm = B // lcm
Alcm = (A - 1) // lcm
print((B - A + 1) - ((Bc - Ac) + (Bd - Ad) - (Blcm - Alcm)))

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

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