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-----
4 9 2 3

-----Sample Output-----
2

5 and 7 satisfy the condition.

Difficulty: introductory

Starter code:

Solutions:
from math import gcd


def f(x):
    return x - (x // C + x // D - x // lcm)


A, B, C, D = list(map(int, input().split()))
lcm = C * D // gcd(C, D)
print((f(B) - f(A - 1)))


#!/usr/bin/env python3
import math


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


def main():

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

    print(ans)


def __starting_point():
    main()

__starting_point()

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

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

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

import math

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

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

c_div=(b//c)-((a-1)//c)
d_div=(b//d)-((a-1)//d)
cd_div=(b//lcm(c,d))-((a-1)//lcm(c,d))

ans=(b-a+1)-((c_div)+(d_div)-(cd_div))
print(ans)

def gcd(a,b):
  while b:a,b=b,a%b
  return a
def lcm(a,b):return a*b//gcd(a,b)
A,B,C,D=map(int,input().split())
def div(x):
    num=x
    num-=x//C
    num-=x//D
    num+=x//lcm(C,D)
    return num
print(div(B)-div(A-1))

import math

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

m = b//c + (-a//c)
n = b//d + (-a//d)
g = c * d // math.gcd(c, d)
p = b//g + (-a//g) 
print(b-a+1-(m+1+n+1-(p+1)))

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

def main():
    A,B,C,D = list(map(int,input().split()))
    #Cで割り切れる数の探索
    tmpC = (A-1)//C
    tmpC2 = (B)//C
    numC = tmpC2 - tmpC
    #Dで割り切れる数の探索
    tmpD = (A-1)//D
    tmpD2 = (B)//D
    numD = tmpD2 - tmpD
    #CでもDで割り切れるもの
    if C == D:
        ans = B-A+1-numC
    else:
        tmpCD = (A-1)//lcm(C,D)
        tmpCD2 = (B)//lcm(C,D)
        numCD = tmpCD2 - tmpCD
        ans = B-A+1-numC-numD+numCD
    return ans
print((main()))


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)

from math import gcd as g

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

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

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

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C_fix
# CreatedDate:  2020-09-03 20:30:23 +0900
# LastModified: 2020-09-03 21:14:03 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


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


def main():
    a, b, c, d = list(map(int, input().split()))
    if (a/c).is_integer():
        c_cnt = b//c - a//c + 1
#        print(b//c, a//c)
    else:
        c_cnt = b//c - a//c
#        print(b//c, a//c)
    if (a/d).is_integer():
        d_cnt = b//d - a//d + 1
#        print(b//d, a//d)
    else:
        d_cnt = b//d - a//d
#        print(b//d, a//d)

    lcm = c * d // gcd(max(c, d), min(c, d))
    if (a/lcm).is_integer():
        lcm_cnt = b//lcm - a//lcm + 1
    else:
        lcm_cnt = b//lcm - a//lcm
#    print(c_cnt, d_cnt, lcm_cnt)
    print((b-a+1-c_cnt-d_cnt+lcm_cnt))


def __starting_point():
    main()

__starting_point()

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)

a,b,c,d=map(int,input().split())
dcou=b//d-(a-1)//d
ccou=b//c-(a-1)//c
from math import gcd
dc=d*c//gcd(d,c)
dccou=b//dc-(a-1)//dc
ans=b-a-dcou-ccou+dccou+1
print(int(ans))

# coding: utf-8


def gcd(m, n):
    if n == 0: return m
    return gcd(n, m % n)

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


def __starting_point():
    main()

__starting_point()

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

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

def num_multi(num, lb, ub): # [lb, ub]にnumの倍数がいくつあるのかを返す
    lR = lb // num
    lQ = lb % num

    uR = ub // num
    # uQ = ub % num

    ans = uR - lR
    if lQ == 0:
        ans += 1

    return ans

print(((B-A+1) - num_multi(C, A, B) - num_multi(D, A, B) + num_multi(lcm, A, B)))


import math
a,b,c,d=list(map(int,input().split()))
lcm=c*d//math.gcd(c,d)
a2=a-(a//c+a//d-a//lcm)
b2=b-(b//c+b//d-b//lcm)
print((b2-a2 if a%c==0 or a%d==0 else b2-a2+1))


import math

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

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

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

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


import math
import collections
import itertools
import copy

def YesNo(Bool):
    if(Bool):
        print("Yes")
    else:
        print("No")
    return

def gcd(a, b):
    """Euclidean Algorithm"""
    while b != 0:
        a, b = b, a % b
    return a

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


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

    Cmin=(A-1)//C
    Dmin=(A-1)//D
    Cmax=B//C
    Dmax=B//D
    LCM=lcm(C,D)
    LCMmin=(A-1)//LCM
    LCMmax=B//LCM

    Cnum=(Cmax - Cmin)
    Dnum=(Dmax - Dmin)
    LCMnum=(LCMmax - LCMmin)

    ans=B-(A-1) - Cnum - Dnum  +LCMnum

    print(ans)


resolve()


import math

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

s1=b//c - (a-1)//c
s2=b//d - (a-1)//d
s12=b//(c*d//math.gcd(c,d)) - (a-1)//(c*d//math.gcd(c,d))
print(b-a+1-(s1+s2-s12))

import math
 
A,B,C,D = map(int,input().split())
 
def F(N):
    # N以下でどちらでも割れない
    x = N//C
    x += N//D
    lcm = C*D//math.gcd(C,D)
    x -= N//lcm
    return N-x
 
answer = F(B) - F(A-1)
print(answer)

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

def lcm(a):
    from math import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x


A, B, C, D = map(int, input().split())
num = []
num.append(C)
num.append(D)
a = A - 1

x_B = B - (B//C) - (B//D) + (B//lcm(num))
x_A = a - (a//C) - (a//D) + (a//lcm(num))

ans = x_B - x_A

print(ans)

import math
A,B,C,D=list(map(int,input().split()))
E=int(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))

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

A, B, C, D = map(int, input().split())
c_multiples = B//C - (A-1)//C
d_multiples = B//D - (A-1)//D
lcm_multiples = B//lcm(C, D) - (A-1)//lcm(C, D)
print(B - A + 1 - c_multiples - d_multiples + lcm_multiples)

import math
 
a,b,c,d=map(int,input().split())
 
n=b-a+1
 
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
  
x=lcm(c,d)
 
cc=b//c-(a-1)//c
dc=b//d-(a-1)//d
xc=b//x-(a-1)//x
 
print(n-cc-dc+xc)

import math
a,b,c,d=map(int,input().split())
e=c*d//math.gcd(c,d)
if a%c==0:
  p=b//c-a//c+1
else:
  p=b//c-a//c
if a%d==0:
  q=b//d-a//d+1
else:
  q=b//d-a//d
if a%e==0:
  r=b//e-a//e+1
else:
  r=b//e-a//e
print(b-a+1-(p+q-r))

from math import gcd

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

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

import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
A,B,C,D = map(int,input().split())
x = B // lcm(C, D) - (A-1) // lcm(C, D)
y = B // C - (A-1) // C
z = B // D - (A-1) // D
ans = (B-A+1) - (y+z-x)
print(ans)

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

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

print(int(f-g))

import fractions

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

def t(tar, l1, l2):
    return (tar - (tar//l1 + tar//l2) + tar//(l1*l2//(fractions.gcd(l1, l2))))

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

import math

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

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

c_num = b // c - (a-1) // c
d_num = b // d - (a-1) // d
base_num = b // base - (a-1) // base

x = int(c_num + d_num - base_num)
print(b-a+1 - x)

from math import gcd
a,b,c,d = map(int,input().split())

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

cntC = b//c - (a-1)//c
cntD = b//d - (a-1)//d
cntE = b//e - (a-1)//e

print((b-a)-(cntC+cntD-cntE)+1)

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

# for文は間に合わないので、包除原理を使え！

# CでもDでも割り切れない =
# 全体(a) - Cで割り切れる(b) + Dで割り切れる(c)
# + CでもDでも割り切れる(d)

# Cで割り切れる個数 =
# B以下の数でCで割り切れる個数 - (A−1)以下の数でCで割り切れる個数

lcm = C*D // math.gcd(C, D)
a = B - A + 1
b = B // C - (A-1) // C
c = B // D - (A-1) // D
d = B // lcm - (A-1) // lcm
 
print(a-b-c+d)

A,B,C,D = map(int,input().split())
import math
E = C*D//math.gcd(C,D)
A -= 1
c = B//C - A//C
d = B//D - A//D
e = B//E - A//E
print(B-A-(c+d-e))

import sys
import math

a, b, c, d = map(int, sys.stdin.readline().split())

lcm = (c * d) // math.gcd(c, d)
div_c = (b // c) - ((a - 1) // c)
div_d = (b // d) - ((a - 1) // d)
div_lcm = (b // lcm) - ((a - 1) // lcm)

print(b - a + 1 - div_c - div_d + div_lcm)

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


from math import *

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

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

print(f-g)

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

nad=B//D
nac=B//C
nid=(A-1)//D
nic=(A-1)//C
nacd=B//(D*C//math.gcd(D,C))
nicd=(A-1)//(D*C//math.gcd(D,C))

ans=B-A+1-(nad-nid)-(nac-nic)+(nacd-nicd)
print((int(ans)))



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

def gcd(x,y):
    if(x == 0):
        return y
    if(y == 0):
        return x
    if(x >= y):
        return gcd(y,x%y)
    if(x < y):
        return gcd(y%x,x)

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

p = B//C - (A-1)//C
q = B//D - (A-1)//D
r = B//l - (A-1)//l
s = p + q - r
print(B-A+1-s)

from math import gcd

def count(x, c, d):
  # x以下のcでもdでも割り切れない奴を数える
  lcm = c // gcd(c, d) * d
  return x - x // c - x // d + x // lcm

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


import math

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

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

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

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

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

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

lcm = lcm(C,D)

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

print((B-A+1 - u_b_ans + u_a_ans))


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

from math import gcd

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

b_div_c = b//c
a_div_c = (a-1)//c

b_div_d =b//d
a_div_d = (a-1)//d

b_div_cd = b//lcm
a_div_cd = (a-1)//lcm



ans1 = b_div_c - a_div_c
ans2 = b_div_d - a_div_d
ans3 = b_div_cd - a_div_cd

ans = b -(a-1) - ans1 - ans2 + ans3
print(ans)

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

# 2数を受け取って最小公倍数を返す関数
import math
def lcm(a, b):
    y = a*b / math.gcd(a, b)
    return int(y)

x = (b - a)+1

# cの倍数の数
cc = (b//c) - ((a-1)//c)

# dの倍数の数
dd = (b//d) - ((a-1)//d)

# cとdの倍数の数
cd = lcm(c,d)
cd = (b//cd) - ((a-1)//(cd))

# cとdの和集合
wa = (cc-cd)+dd

print(x-wa)

import math

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

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

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

import math

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

def kazu(s,e,n):
  if s%n>0:
    s2=s-s%n
    s2+=n
  else:
    s2=s
  e2=e-e%n
  if s<=s2<=e and s<=e2<=e:
    return ((e2-s2+n)//n)
  return 0

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

nc = kazu(a,b,c)
nd = kazu(a,b,d)
ncd = kazu(a,b,lcm(c,d))

ans = b-a+1

ans -= nc
ans -= nd
ans += ncd

print(ans)


import math
#import itertools
#import numpy as np
#from collections import deque
# sys.setrecursionlimit(10 ** 6)
#MOD = 10 ** 9 + 7
#INF = 10 ** 9
#PI = 3.14159265358979323846

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    a,b,c,d=INTM()
    lcm=(c*d)//math.gcd(c,d)
    a-=1
    ct_a=a-(a//c)-(a//d)+(a//lcm)
    ct_b=b-(b//c)-(b//d)+(b//lcm)
    print(ct_b-ct_a)
    
def __starting_point():
    do()
__starting_point()

import sys
import math

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    a, b, c, d = inl()
    cd = c * d // math.gcd(c, d)
    r1 = b // c + b // d - b // cd
    r2 = (a - 1) // c + (a - 1) // d - (a - 1) // cd
    ans = (b - r1) - (a - 1 - r2)
    return ans


print(solve())


import sys
import math
from collections import defaultdict, deque, Counter
from copy import deepcopy
from bisect import bisect, bisect_right, bisect_left
from heapq import heapify, heappop, heappush
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]

def gcd2(i, past):
    return i * past // math.gcd(i, past)
    
def main():
    A, B, C, D = MI()
    AC = (A-1) // C
    BC = B // C
    
    AD = (A-1)//D
    BD = B//D
    
    ACD = (A-1)//(gcd2(C, D))
    BCD = B//(gcd2(C, D))
    
    ans = (BC + BD - BCD) - (AC + AD - ACD)
    print(B-A+1-ans)
    
    
    
def __starting_point():
    main()
__starting_point()

import math as m
A,B,C,D=map(int,input().split())
A-=1
g=C*D//m.gcd(C,D)
x=B//C-A//C
y=B//D-A//D
z=B//g-A//g
print(B-A-x-y+z)

import math

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

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

l=lcm(C,D)

temp=l-(l//C+l//D-1)

a=(A-1)%l
b=B%l

aa=(A-1)//l
bb=B//l

tempA=a-(a//C+a//D-1)
tempB=b-(b//C+b//D-1)
            

ans=temp*bb+tempB-(temp*aa+tempA)


print(ans)


import math

def solve(a,c,d):
    x=a+1
    x-=a//c+1
    x-=a//d+1
    x+=a//(c*d//math.gcd(c,d))+1
    return x

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


import math
a,b,c,d=map(int,input().split())
n,m,k=0,0,0

if a%c==0:
    n=b//c-a//c+1
else:
    n=b//c-a//c
if a%d==0:
    m=b//d-a//d+1
else:
    m=b//d-a//d
e=(c*d)//math.gcd(c,d)
if a%e==0:
    k=b//e-a//e+1
else:
    k=b//e-a//e
k=n+m-k
print(b-a-k+1)

import math
A, B, C, D = map(int, input().split(' '))
CD_least_common = C * D // math.gcd(C, D)
except_rst = B // C - (A - 1) // C + B // D - (A - 1) // D - (B // CD_least_common - (A - 1) // CD_least_common)
rst = B - (A - 1) - except_rst
print(rst)

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

Ac = (A-1)//C
Ad = (A-1)//D
Acd = (A-1)//lcm(C,D)
Bc = B//C
Bd = B//D
Bcd = B//lcm(C,D)

c = Bc-Ac
d = Bd-Ad
cd = Bcd-Acd

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

# coding: utf-8
# Your code here!

from math import gcd

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

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

a,b,c,d=(int(x) for x in input().split())

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

print(ans)

import math
a,b,c,d = map(int,input().split())
divc = b // c - (a-1) // c
divd = b // d - (a-1) // d
cd = b // ((c * d) // math.gcd(c,d)) - (a-1) // ((c * d) // math.gcd(c,d))
print(b - a - divc - divd + cd + 1)

import math

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

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

import math
 
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
 
a,b,c,d=map(int,input().split())
 
c_div=(b//c)-((a-1)//c)
d_div=(b//d)-((a-1)//d)
cd_div=(b//lcm(c,d))-((a-1)//lcm(c,d))
 
ans=(b-a+1)-((c_div)+(d_div)-(cd_div))
print(ans)

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

import math
A,B,C,D=map(int,input().split())
if A%C==0:
    divC=B//C-A//C+1
else:
    divC=B//C-A//C
if A%D==0:
    divD=B//D-A//D+1
else:
    divD=B//D-A//D
lcm=C*D//math.gcd(C,D)
if A%lcm==0:
    divlcm=B//lcm-A//lcm+1
else:
    divlcm=B//lcm-A//lcm
print(B-A+1-divC-divD+divlcm)

import math

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

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

pac, qac = divmod(A, C)
pad, qad = divmod(A, D)
pacd, qacd = divmod(A, cd)

pbc, qbc = divmod(B, C)
pbd, qbd = divmod(B, D)
pbcd, qbcd = divmod(B, cd)

pac = pac - 1 if qac == 0 else pac
pad = pad - 1 if qad != 0 else pad
pacd = pacd - 1 if qacd != 0 else pacd

ans = (pbc + pbd - pbcd) - (pac + pad - pacd)
print((B - A - ans + 1))



a,b,c,d = map(int,input().split())
x,y = c,d
while y != 0:
    x,y = y,x%y
lcm = c * d // x
c_upper = b // c
c_lower = -(-a // c)
d_upper = b // d
d_lower = -(-a // d)
lcm_upper = b // lcm
lcm_lower = -(-a // lcm)
print((b-a+1)-(c_upper-c_lower+1)-(d_upper-d_lower+1)+(lcm_upper-lcm_lower+1))

import math

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

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

z = f(c, d)
print(b - a + 1 - ((b//c - (a-1)//c) + (b//d - (a-1)//d) - (b//z - (a-1)//z)))

import math
a,b,c,d = map(int,input().split())
e = c*d//math.gcd(c,d)
wa = 0
c_seki = b//c-(a-1)//c
d_seki = b//d-(a-1)//d
e_seki = b//e-(a-1)//e
wa = c_seki+d_seki-e_seki
print(b-a+1-wa)

import math

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

s1=b//c - (a-1)//c
s2=b//d - (a-1)//d
s12=b//(c*d//math.gcd(c,d)) - (a-1)//(c*d//math.gcd(c,d))
#print(s1,s2,s12)
print((b-a+1-(s1+s2-s12)))


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

def mul_count(v,w,n):
  if v % n == 0:
    s = v//n
  else:
    s = v//n + 1
  e = w // n
  if s > e:
    return 0
  else:
    return e - s + 1

def koyaku(x,y):
  big = max(x,y)
  small= min(x,y)
  amari = big % small
  if amari == 0:
    return small
  else:
    return koyaku(small,amari)

c_mul = mul_count(a,b,c)
d_mul = mul_count(a,b,d)

cd_common = koyaku(c,d)
cd_mul = c * d // cd_common
common_mul = mul_count(a,b,cd_mul)
yobun = c_mul + d_mul - common_mul
print((b - a + 1 - yobun))


import math

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

A -= 1

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

print(B - B//C - B//D + B//lcm - A + A//C + A//D - A//lcm)

import math

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

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

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

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


import sys

def gcd(a, b):
    """
    最大公約数を求める
    """
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    """
    最小公倍数を求める
    """
    return a*b//(gcd(a, b))


input = sys.stdin.readline

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

div_ac = (a-1) // c
div_bc = b // c


div_ad = (a-1) // d
div_bd = b // d

lcm_cd = lcm(c,d)

div_acd = (a-1) // lcm_cd
div_bcd = b // lcm_cd

a_1_result =  div_ac + div_ad - div_acd
b_result = div_bc + div_bd - div_bcd

print(((b+1 - a) - (b_result - a_1_result)))


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

def main():
  A, B, C, D = map(int, input().split())
  E = lcm(C, D)
  a_c, a_d, a_cd = (A-1) // C, (A-1) // D, (A-1) // E
  b_c, b_d, b_cd = B // C, B // D, B // E
  a, b = a_c + a_d - a_cd, b_c + b_d - b_cd
  ans = (B - A + 1) - (b - a)
  print(ans)
  
main()

import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    A, B, C, D = LI()

    # X以下の自然数でCでもDでも割り切れないものの個数
    def f(X):
        ret = X - X // C - X // D + X // (C * D // math.gcd(C, D))
        return ret

    ans = f(B) - f(A - 1)
    print(ans)

def __starting_point():
    resolve()

__starting_point()

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

cyaku=b//c
dyaku=b//d


cds=b//((c*d)//(math.gcd(c,d)))

x=b-(cyaku+dyaku-cds)

cyaku2=(a-1)//c
dyaku2=(a-1)//d

cds2=(a-1)//((c*d)//(math.gcd(c,d)))

y=(a-1)-(cyaku2+dyaku2-cds2)

print(x-y)

from functools import reduce
from math import gcd

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

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

import math

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

n=b-a+1

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

cc=b//c-(a-1)//c
dc=b//d-(a-1)//d
xc=b//x-(a-1)//x

print(n-cc-dc+xc)

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


def calc(x):
    nonlocal c, d
    l = c // math.gcd(c, d) * d
    return x - x // c - x // d + x // l


print((calc(b) - calc(a - 1)))


a,b,c,d=map(int,input().split())
a-=1
def gcd(a,b):
    if b==0: return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)
aa= b//c-a//c 
bb= b//d-a//d 
cc= b//lcm(c,d)- a//lcm(c,d)
print(b-a-(aa+bb-cc))

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

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

Cwareru=B//C-(A-1)//C
Dwareru=B//D-(A-1)//D
CDwareru=B//lcm(C,D)-(A-1)//lcm(C,D)
#print(Cwareru,Dwareru,CDwareru)
print(B-A+1-(Cwareru+Dwareru-CDwareru))

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

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


import math

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

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

B_s=B-B//C-B//D+B//CD_lcm
A_s=(A-1)-(A-1)//C-(A-1)//D+(A-1)//CD_lcm
print(B_s-A_s)

import sys
import math

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

bc = B // C
bd = B // D
bg = B // lcm
ac = (A-1) // C
ad = (A-1) // D
ag = (A-1) // lcm

print(B - A + 1 - (bc - ac) - (bd - ad) + (bg - ag))

import math
A, B, C, D = map(int, input().split())
 
# CでもDでも割り切れない = 全体(a) - Cで割り切れる(b) + Dで割り切れる(c) + CでもDでも割り切れる(d)
lcm = C*D // math.gcd(C, D)
a = B - A + 1
b = B // C - (A-1) // C
c = B // D - (A-1) // D
d = B // lcm - (A-1) // lcm

print(a-b-c+d)

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

# AtCoder Beginner Contest 131
# C - Anti-Division
import math

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

A,B,C,D=list(map(int,input().split()))
bc=B//C
ac=(A-1)//C
cnum=bc-ac

bd=B//D
ad=(A-1)//D
dnum=bd-ad


lcmcd=lcm(C,D)
blcmcd=B//lcmcd
alcmcd=(A-1)//lcmcd
lcmcdnum=blcmcd-alcmcd


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


import math

a, b, c, d = map(int, input().split())
l = c * d // math.gcd(c, d)
all = b - a + 1
can_c = b // c - (a - 1) // c
can_d = b // d - (a - 1) // d
can_cd = b // l - (a - 1) // l
ans = all - can_c - can_d + can_cd
print(ans)

import math

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

num_C_baisu = B//C - (A-1)//C #(math.ceil(A/C) - 1)

num_D_baisu = B//D - (A-1)//D #(math.ceil(A/D) - 1)

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

num_CD_baisu = B//CD - (A-1)//CD #(math.ceil(A/CD) - 1)

baisu_num = num_C_baisu + num_D_baisu - num_CD_baisu

print(B-A+1-baisu_num)

import math
def lcm(a):
    LCM = a[0]
    for i in range(1, len(a)):
        LCM = LCM * a[i] // math.gcd(LCM, a[i])
    return LCM

def f(k):
    return b//k - (a-1)//k

a, b, c, d = map(int, input().split())
ALL = b - a + 1
ans = ALL - (f(c) + f(d) - f(lcm([c,d])))
print(ans)

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

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

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

print(int(ans))

def gcd(x, y):
    if y == 0:
        return x
    
    r = x % y
    return gcd(y, r)

A, B, C, D = [int(x) for x in input().split()]
if C > D:
    E = C * D // gcd(C, D)
else:
    E = C * D // gcd(D, C)

divC = B // C - (A - 1) // C
divD = B // D - (A - 1) // D
divE = B // E - (A - 1) // E
div = divC + divD - divE
ans = B - A + 1 - div

print(ans)

# ABC 131 C
import math
[A, B, C, D] = [int(i) for i in input().split()]
u = int((C*D)/math.gcd(C, D))
s = B//C - A//C + B//D - A//D - B//(u) + A//(u) + 1
t = 0
if A%C != 0:
    t -= 1
if A%D != 0:
    t -= 1
if A%u != 0:
    t += 1
s += t

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

import math
a,b,c,d=map(int,input().split())
p = c * d // math.gcd(c, d)
x = b//c + b//d - b//p -((a-1)//c + (a-1)//d - (a-1)//p)
ans = b-a+1 -x
print(ans)

import math

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

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

print(split_b-split_a)

import math

A,B,C,D = list(map(int,input().split()))
divAC,modAC = divmod(A,C)
divBC,modBC = divmod(B,C)
ans = 0
if modAC == 0:
    ans += divBC - divAC + 1
else:
    ans += divBC - divAC

divAD,modAD = divmod(A,D)
divBD,modBD = divmod(B,D)
if modAD == 0:
    ans += divBD - divAD + 1
else:
    ans += divBD - divAD
divACD,modACD = divmod(A,int(C * D / math.gcd(C, D)))
divBCD,modBCD = divmod(B,int(C * D / math.gcd(C, D)))
if modACD == 0:
    ans -= divBCD - divACD + 1
else:
    ans -= divBCD - divACD

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



# 解説動画みた： https://www.youtube.com/watch?v=XI8exXVxZ-Q
# 最小公倍数
# ユーグリッドの互除法

import math

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

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().split())
ans = f(b, d, c) - f(a-1, c, d)
print(ans)

import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
A, B, C, D = map(int,input().split())
Cres = B//C - (A-1)//C
Dres = B//D - (A-1)//D
CDres = B//lcm(C,D) - (A-1)//lcm(C,D)
print(B-A+1-(Cres + Dres - CDres))

def gcd(a,b):
    while b:a,b=b,a%b
    return a
def lcm(c,d):return c*d//gcd(c,d)
def div(x):
    num=x
    num-=x//C
    num-=x//D
    num+=x//lcm(C,D)
    return num
A,B,C,D=map(int,input().split())
print(div(B)-div(A-1))

import math


def cnt(a: int, k: int):
    return a // k


def num(a, c, d):
    m_a_c = cnt(a, c)
    m_a_d = cnt(a, d)
    m_a_cd = cnt(a, c * d // math.gcd(c, d))
    return a - m_a_c - m_a_d + m_a_cd


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



def main():
    import fractions

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

    d_c = b // c - (a-1) // c
    d_d = b // d - (a-1) // d

    cd = c * d // fractions.gcd(c, d)
    d_cd = b // cd - (a - 1) // cd

    print((b-a + 1 - (d_c + d_d - d_cd)))


def __starting_point():
    main()


__starting_point()