# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations  # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
# If the element is already present in the list,

# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect

# If the element is already present in the list,
# the right most position where element has to be inserted is returned

# ==============================================================================================
# fast I/O region

BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType

def iterative(f, stack=[]):
    def wrapped_func(*args, **kwargs):
        if stack: return f(*args, **kwargs)
        to = f(*args, **kwargs)
        while True:
            if type(to) is GeneratorType:
                stack.append(to)
                to = next(to)
                continue
            stack.pop()
            if not stack: break
            to = stack[-1].send(to)
        return to

    return wrapped_func

#### END ITERATE RECURSION ####

# ===============================================================================================
# some shortcuts

mod = 1000000007

def inp(): return sys.stdin.readline().rstrip("\r\n")  # for fast input

def out(var): sys.stdout.write(str(var))  # for fast output, always take string

def lis(): return list(map(int, inp().split()))

def stringlis(): return list(map(str, inp().split()))

def sep(): return map(int, inp().split())

def strsep(): return map(str, inp().split())

def fsep(): return map(float, inp().split())

def nextline(): out("\n")  # as stdout.write always print sring.

def testcase(t):
    for p in range(t):
        solve()

def pow(x, y, p):
    res = 1  # Initialize result
    x = x % p  # Update x if it is more , than or equal to p
    if (x == 0):
        return 0
    while (y > 0):
        if ((y & 1) == 1):  # If y is odd, multiply, x with result
            res = (res * x) % p

        y = y >> 1  # y = y/2
        x = (x * x) % p
    return res

from functools import reduce

def factors(n):
    return set(reduce(list.__add__,
                      ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

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

# N=100000
# mod = 10**9 +7
# fac = [1, 1]
# finv = [1, 1]
# inv = [0, 1]
#
# for i in range(2, N + 1):
#     fac.append((fac[-1] * i) % mod)
#     inv.append(mod - (inv[mod % i] * (mod // i) % mod))
#     finv.append(finv[-1] * inv[-1] % mod)
#
#
# def comb(n, r):
#     if n < r:
#         return 0
#     else:
#         return fac[n] * (finv[r] * finv[n - r] % mod) % mod

##############Find sum of product of subsets of size k in a array
# ar=[0,1,2,3]
# k=3
# n=len(ar)-1
# dp=[0]*(n+1)
# dp[0]=1
# for pos in range(1,n+1):
#     dp[pos]=0
#     l=max(1,k+pos-n-1)
#     for j in range(min(pos,k),l-1,-1):
#         dp[j]=dp[j]+ar[pos]*dp[j-1]
# print(dp[k])

def prefix_sum(ar):  # [1,2,3,4]->[1,3,6,10]
    return list(accumulate(ar))

def suffix_sum(ar):  # [1,2,3,4]->[10,9,7,4]
    return list(accumulate(ar[::-1]))[::-1]

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

# =========================================================================================
from collections import defaultdict

def numberOfSetBits(i):
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24

def N():
    return int(inp())

def solve():
    n,a,b,p,q=sep()
    ans=0
    ans+=(p*(n//a) + q*(n//b))
    m=min(p,q)
    ans-=(m*(n//lcm(a,b)))
    print(ans)

solve()
#testcase(int(inp()))

from math import gcd

n, a, b, p, q = map(int, input().split())

ans = p * (n // a) + q * (n // b) - min(p, q) * (n // ((a * b) // gcd(a, b)))

print(ans)

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

s=raw_input().split()
n=int(s[0])
a=int(s[1])
b=int(s[2])
p=int(s[3])
q=int(s[4])

red=n/a
blue=n/b
redblue=n*gcd(a,b)/(a*b)
if p>q:
	print p*red+q*(blue-redblue)
else:
	print p*(red-redblue)+q*(blue)

import fractions
n,a,b,p,q=map(int,raw_input().split())
s=a*b/fractions.gcd(a,b)
print n/a*p+n/b*q-(n/s)*min(p,q)

import math
n, red, blue, red_cost, blue_cost = map(int, input().split())
reds = n//red - n//((red*blue)//math.gcd(red,blue))
blues = n//blue - n//((red*blue)//math.gcd(red,blue))
ans = reds*red_cost + blues*blue_cost + max(blue_cost, red_cost)*(n//((red*blue)//math.gcd(red,blue)))
print(int(ans))

liste = input().split(" ")

n = int(liste[0])
a = int(liste[1])
b = int(liste[2])
p = int(liste[3])
q = int(liste[4])

m = max(p,q)
res = 0
multa = a
multb = b

# for i in range (1,n+1) :
#     auxa = False
#     auxb = False
#     if i == multa :
#         auxa = True
#         multa += a
#     if i == multb :
#         auxb = True
#         multb += b
#     if auxa and auxb :
#         res += m
#     else :
#         if auxa :
#             res += p
#         elif auxb :
#             res += q
#     #print(i,res)
#
# print(res)

def pgcd(a,b):
    """pgcd(a,b): calcul du 'Plus Grand Commun Diviseur' entre les 2 nombres entiers a et b"""
    while b!=0:
        a,b=b,a%b
    return a

ppcm = a*b /pgcd(a,b)

diva = n//a
divb = n//b
divab = int(n //ppcm)

if m == p :
    print(diva*p + (divb-divab)*q)
else :
    print(divb*q + (diva-divab)*p)

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

n, a, b, p, q = map(int, raw_input().split())

count = 0

count += n/a * p
count += n/b * q

count -= min(p, q) * (n/((a*b)/gcd(a, b)))

print count

from math import gcd as g

def lmc(a, b):
    return a // g(a, b)*b

n, a, b, p, q = map(int, input().split())
ans = 0

ans += (n//a)*p
ans += (n//b)*q
ans -= (n//lmc(a, b))*min(p, q)

print(ans)

"""
tr = False if p > q else True

for i in range(1, n+1):
    if not(tr):
        if i % a == 0:
            ans += p
        elif i % b == 0:
            ans += q
    else:
        if i % b == 0:
            ans += q
        elif i % a == 0:
            ans += p
print(ans)
"""

n,a,b,p,q=map(int,input().split())
def gcd(x, y):
    while y != 0:
        (x, y) = (y, x % y)
    return x
lcm=a*b//gcd(a,b)
ans=(n//a)*p + (n//b)*q - (n//lcm)*min(p,q)
print(ans)

from fractions import gcd

def lcm(numbers):
    return reduce(lambda x, y: (x * y) / gcd(x, y), numbers, 1)

entrada = map(int, raw_input().split())
n = entrada[0]
a = entrada[1]
b = entrada[3]
p = entrada[2]
q = entrada[4]
result = long()

if b >= q:
    result += (n / a) * b + (n / p) * q - (n / lcm((a, p))) * q
else:
    result += (n / p) * q + (n / a) * b - (n / lcm((a, p))) * b

print result

from math import gcd

n, a, b, p, q = map(int, input().split())

# print(n, a, b, p, q)
x = n // a * p
y = n // b * q
z = (n // (a * b // gcd(a, b))) * min(p, q)

print(x + y - z)

from fractions import gcd
n,a,b,p,q = map(int,raw_input().split())
ab = (a*b)/gcd(a,b)
print (n/a - n/ab) * p + (n/b - n/ab) * q + n/ab * max(p,q)

from math import gcd
n,a,b,p,q=map(int,input().split())
x=min(p,q)
l=a*b//gcd(a,b)
print((n//a)*p+(n//b)*q-(n//l)*x)

import math
n, a, b, p, q = map(int, input().split())
lcm = int(a*b/math.gcd(a, b))
ans = 0
if p >= q:
	ans = n//a*p + n//b*q - n//lcm*q
else:
	ans = n//b*q + n//a*p - n//lcm*p
print(int(ans))

def compute():

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

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

    n, a, b, p, q = map(int,input().split())
    return (n//a)*p + (n//b)*q - (n//(lcm(a,b)))*min(p,q)

if __name__=="__main__":
    print(compute())

L=input().split()
n=int(L[0])
a=int(L[1])
b=int(L[2])
p=int(L[3])
q=int(L[4])

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

c=int((a*b/pgcd(a,b)))

d=int(n//c)

S=int(((n//a)-d)*p+((n//b)-d)*q+d*max(p,q))

print(S)

import sys

# inData = sys.argv[1:]
inData = input().split()

n, a, b, p, q = map(int, inData)

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

cmmmc = int((a * b) / cmmdc(a, b))

print(int(int((n / a)) * p + int((n / b)) * q - int((n / cmmmc)) * (min(p, q))))

line = input().split(' ')
n = int(line[0])
a = int(line[1])
b = int(line[2])
p = int(line[3])
q = int(line[4])

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

def MIN(a,b):
    if a >= b :
        return b
    else :
        return a

ans = int(n/a) * p
ans += int(n/b) * q

GCD = findGCD(a,b)
LCM = (a / GCD)  * (b / GCD) * GCD
ans -= int(n/ LCM) * MIN(p,q)

print(ans)

#!/usr/bin/python3
# Copyright (C) 2016 Sayutin Dmitry.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; version 3
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see <http://www.gnu.org/licenses/>.

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

n, a, b, p, q = map(int, input().split())

s = (n // a) * p + (n // b) * q
s -= (n // (a * b // gcd(a, b))) * min(p, q)
print(s)

l=input()
l=l.split(' ')
q=int(l.pop())
p=int(l.pop())
b=int(l.pop())
a=int(l.pop())
n=int(l.pop())
somme=0
"""
if p>q:
    somme+=p*(n//a)
    for j in range(1,(n//b)+1):
            if (b*j)%a!=0:
                somme+=q
else:
    somme+=q*(n//b)
    for j in range(1,(n//a)+1):
            if (a*j)%b!=0:
                somme+=p
"""
def pgcd(x,y):
    if y==0:
        return x
    else:
        return pgcd(y,x%y)
d=pgcd(a,b)
alpha=a//d
beta=b//d
if p>q:
    somme+=p*(n//a)
    somme+=q*(n//b-(n//b)//alpha)
else:
    somme+=q*(n//b)
    somme+=p*(n//a-(n//a)//beta)

print(somme)

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

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

n, a, b, p, q = list(map(int, input().split()))

if p < q:
	a, b = b, a
	p, q = q, p

nok = get_nok(a, b)

t = n // a
minus = n // nok
c = n // b
print(t * p + q * (c - minus))

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

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

n,a,b,p,q = map(int, input().split())
A = n//a
B = n//b
AandB = n//lcm(a,b)

print(A*p + B*q - min(p,q)*AandB)

def gcd (x, y):
    while y:
        x, y = y, x % y
    return x
n, a, b, p, q = map(int, input().split())
if (p > q): a, b, p, q = b, a, q, p
print(p * (n // a - n * gcd(a, b) // a // b) + q * (n // b))

from math import floor, ceil, gcd
n, a, b, p, q = map(int, input().split())
pc = floor(n / a) - ceil(1 / a) + 1
qc = floor(n / b) - ceil(1 / b) + 1
l = (a * b) // gcd(a, b)
bc = floor(n / l) - ceil(1 / l) + 1
pc -= bc
qc -= bc
ans = p * pc + q * qc
if (p >= q):
    ans += (p * bc)
else:
    ans += (q * bc)
print(ans)

import math
def lcm(a, b):
	return (a*b)//math.gcd(a, b)
n,a,b,p,q = map(int, input().split())
both = (n//lcm(a,b))
ans = (both)*max(p,q) + ((n//a - both) * p) + ((n//b - both) * q);
print(ans)

from math import gcd

while True:
        try:
                n, a, b, p, q = map(int, input().split())
                s = (n // a) * p
                s += (n // b) * q
                s -= (n // ((a * b) // gcd(a, b))) * min(p, q)
                print(int(s))
        except EOFError:
                break

n, a, b, p, q = map(int, input().split())
r, t = a, b

while a != 0 and b != 0:
    if a > b:
        a = a % b
    else:
        b = b % a

nod = a + b
nok = r * t // nod

print((n // nok * max(p, q)) + (((n // r) - (n // nok)) * p) + (((n // t) - (n // nok)) * q))

import fractions
n,a,b,p,q=map(int,input().split())
nok=a*b//fractions.gcd(a,b)
if p>q:
    a,b,p,q=b,a,q,p
print((n//b)*q+(n//a-n//nok)*p)

# -*- coding: utf-8 -*-
"""
Created on Mon Jun 13 21:55:56 2016

@author: Dell_
"""

import sys
if False:
    input = open('chocolate.txt', 'r')
else:
    input = sys.stdin
x = 0
numbers = input.readline().split()

n = int(numbers[0])
a = int(numbers[1])
b = int(numbers[2])
p = int(numbers[3])
q = int(numbers[4])

chocolates = 0
numBoth = 0
numA = n//a
numB = n//b

def HCF(a,b):
    while b > 0:
        t = b
        b = a%b
        a = t
    return a

def LCM(a, b):
    lcm = (a*b) // (HCF(a,b))
    return lcm

numBoth = n // LCM(a, b)

choca = numA * p
chocb = numB * q

if p > q:
    chocolates = choca + chocb - (numBoth*q)
elif p < q:
    chocolates = choca + chocb - (numBoth*p)
elif p == q:
    chocolates = choca + chocb - (numBoth*p)
print chocolates

from sys import stdin
def gcd(a,b):
 while a%b:
  t = a%b; a=b; b=t
 return b
def lcm(a,b):
 return (a*b)/gcd(a,b)
n,a,b,p,q = map(int,stdin.readline().split())
fir = n/a
sec = n/b
com = n/lcm(a,b)
fir -= com
sec-=com
ans = fir*p + sec*q
if p>q:
 ans+= com*p
else:
 ans+=com*q
print ans

from fractions import gcd

n, a, b, p, q = map(int, raw_input().split())
lcm = a * b / gcd(a, b)

tot = p * (n / a) + q * (n / b)

if p * (n / lcm) > q * (n / lcm):
    tot -= q * (n / lcm)
else:
    tot -= p * (n / lcm)

print tot

from sys import stdin
from fractions import gcd

rints = lambda: [int(x) for x in stdin.readline().split()]
lcm = lambda a, b: a // gcd(a, b) * b

n, a, b, p, q = rints()
diva, divb, lc = n // a, n // b, lcm(a, b)
divab = n // lc
print((diva - divab) * p + (divb - divab) * q + divab * max(p, q))

from math import floor, gcd
def mmc(x, y):
	maior = max(x, y)
	while True:
		mmc = (x * y) // gcd(x,y)
		return mmc

a,b,c,d,e = map(int, input().split())
resp = d * (floor(a // b))
resp += e * (floor(a // c))
resp -= min(d,e) * (a // (mmc(b,c)))
print(resp)

from fractions import gcd
def lcm(a, b): return a * b / gcd(a, b)
n, a, b, p, q = map(int, raw_input().split())
print (n / a) * p + (n / b) * q - (n / lcm(a, b)) * min((p, q,))

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

entrada = map(int, raw_input().split())

N = entrada[0]
a = entrada[1]
b = entrada[2]
p = entrada[3]
q = entrada[4]

diva = N/a
divb = N/b
divab = N/((a*b)/mdc(a,b))

print (diva*p) + (divb*q) - (divab*min(p,q))

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

n,a,b,p,q=list(map(int,input().split()))
c=(a*b)//gcd(a,b)
if p>q:
    d=n//a-n//c
    e=n//b-n//c
    print(d*p+e*q+p*(n//c))
else:
    d=n//a-n//c
    e=n//b-n//c
    print(d*p+e*q+q*(n//c))

import sys

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

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

n, a, b, p, q = map(int, input().split())

As = n//a
Bs = n//b
if a==b:
   print(As*max(p,q))
   sys.exit()

common = lcm(a,b)
com = n//common

if p>q:
   Bs = Bs - com
   print(As*p + Bs*q)
else:
   As = As - com
   print(As*p + Bs*q)

import sys
input = sys.stdin.readline

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

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

n,a,b,p,q = (int(x) for x in input().split())
if (p > q):
    nn = n // a
    ans = (n // a) * p + ((n // b) - (n // lcm(a,b))) * q
else:
    ans = (n // b) * q + ((n // a) - (n // lcm(a,b))) * p
print(ans)

# -*- coding: utf-8 -*-
def gcd(a, b):
    if (b == 0): return a
    return gcd(b, a % b)

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

n, a, b, p, q = map(int, raw_input().split())

a_divisor = int(n / a)
b_divisor = int(n / b)
common_divisor = int(n/ lcm(a, b))

print a_divisor * p + b_divisor * q - common_divisor * min(p, q)

n,a,b,p,q=map(int,raw_input().split())
def mdc(x,y):
    if y==0:
        return x
    return mdc(y,x%y)
k=max(a,b)/mdc(a,b)*min(a,b)
print n/k*max(p,q)+(n/a-n/k)*p+(n/b-n/k)*q

def MDC(a,b):

	while a % b != 0:

		aux = b

		b = a  % b

		a = aux

	return b

def MMC(a,b):

	return (a*(b/MDC(a,b)))

n, a, b, p, q = map(int, raw_input().split())

divisiveisA = n / a
divisiveisB = n / b

comuns = n / MMC(a,b)

resultado = divisiveisA * p + divisiveisB * q - comuns * (min(p,q))

print resultado

import sys
from math import gcd

n, a, b, p, q = map(int, input().split())
ans = (n // a) * p + (n // b) * q - (n // (a * b // gcd(a, b))) * min(p, q)
print(ans)

from fractions import gcd
n,a,b,p,q=map(int,raw_input().split())
x=n/a
y=n/b
z=(a*b)/gcd(a,b)
z=n/z
if p>q:
	ans=x*p+(y-z)*q
else:
	ans=y*q+(x-z)*p
print ans

II = lambda: int(raw_input())
IAI = lambda: map(int, raw_input().split())
IL = lambda: raw_input().strip()
IAS = lambda: raw_input().split()

from fractions import gcd
n,a,b,p,q = IAI()

print n / a * p + n / b * q + n / (a*b/gcd(a, b)) * (max(p,q) - p - q)

def find(a,b):
    if(b==0):
        return a
    else:
        return find(b,a%b)
n,a,b,p,q=map(int,raw_input().strip().split(" "))
lcm=(a*b)/find(a,b)
m=n/lcm
print ((n/a)-m)*p+((n/b)-m)*q+m*(max(p,q))

import fractions
n,a,b,p,q=map(int,raw_input().split())
s=a*b/fractions.gcd(a,b)
print n/a*p+n/b*q-(n/s)*min(p,q)

import math
n,a,b,p,q = map(int,input().split())
x = n//a
y = n//b
z = n//((a*b)//math.gcd(a,b))
ans = (x-z)*p + (y-z)*q + z*max(p,q)
print(ans)

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

N,a,b,p,q = map(int, raw_input().split(' '))
divisao_a = N/a
divisao_b = N/b
divisao_aEb = N/((a*b)/mdc(a,b))

print (divisao_a*p) + (divisao_b*q) - (divisao_aEb*min(p,q))

def gcd(a,b):
	if b==0:
		return a
	return gcd(b,a%b)
def lcm(a,b):
	return a*b/(gcd(a,b))
n,a,b,p,q = map(int,raw_input().split())
pq = max(p,q)
x = int(n/a)
y = int(n/b)
l = lcm(max(a,b),min(a,b))
ans = p*x + q*y - (p+q)*(n/l)
ans += max(p,q)*(n/l)
print ans

import math
import sys
sys.setrecursionlimit(10000)
def gcd(a, b):
    return b if a % b == 0 else gcd(b, a % b)

def lcm(a, b):
    return a*b/gcd(a,b)
s = raw_input()
n, a, b, p, q = s.split()
n = int(n)
a = int(a)
b = int(b)
p = int(p)
q = int(q)
res = n / a * p + n / b * q - n / lcm(a, b) * (p + q)
res += n/ lcm(a, b) * max(p, q)

print res

import math
n,a,b,p,q=map(int, input().split())
print((n//a)*p+(n//b)*q-(n//((a*b)// math.gcd(a,b)))*min(p,q))

from math import gcd

def main():
    n, a, b, p, q = map(int, input().split())
    g = gcd(a, b)
    lcm = a * b // g
    fa = n // a
    fb = n // b
    fab = n // lcm
    print((fa - fab) * p + (fb - fab) * q + fab * max(p, q))

if __name__ == '__main__':
    main()

n,red,blue,red_candy,blue_candy = map(int,raw_input().split())
total = 0
def mdc(a, b):
    while b:
        a, b = b, a%b
    return a
def mmc(a,b):
	return (a*b)/mdc(a,b)
if red_candy>=blue_candy:
	maximo = red
	maximo_valor = red_candy
	minimo = blue
	minimo_valor = blue_candy
else:
	maximo = blue
	maximo_valor = blue_candy
	minimo = red
	minimo_valor = red_candy
total = ((n/maximo) * maximo_valor) + ((n/minimo) * minimo_valor) - (n / mmc(maximo,minimo)) * minimo_valor
print total

from sys import stdin, stdout

def gcd(a, b):
    if not b:
        return a

    return gcd(b, a % b)

n, a, b, p, q = map(int, stdin.readline().split())
first, second, third = (n // a) * p, (n // b) * q, (n // (a * b // gcd(a, b))) * min(p, q)
stdout.write(str(first + second - third))

import sys,math
n,a,b,p,q=map(int,sys.stdin.readline().split())
x=(n//a)*p
x+=(n//b)*q
lcm=(a*b)//math.gcd(a,b)
x-=(n//lcm)*(min(p,q))
print(x)

from fractions import gcd
n , a , b , p , q = map(int , raw_input().split())

pro  = (a*b)/gcd(a,b)

val1 = n / a
val2 = n / b
val3 = n / pro

ans = val3 * max(p , q) + (val1 - val3)* p + (val2 - val3)*q

print ans

#import sys
#sys.stdin = open('in', 'r')
#n = int(input())
#a = [int(x) for x in input().split()]

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

n,a,b,p,q = map(int, input().split())

if q > p:
    a,b = b,a
    p,q = q,p

res = (n//a)*p + (n//b)*q - (n//(a*b//gcd(a,b)))*q

print(res)

from fractions import gcd
def lcm(x, y):
   return (x*y)//gcd(x,y)
n,a,b,p,q=map(int,raw_input().split())
c=n/lcm(a,b)
print ((n/a)*p)+((n/b)*q)-(min(p,q)*c)

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

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

n, a, b, p, q = map(int, input().split())
sum = 0
sum+=(n//a-n//lcm(a,b))*p
sum+=(n//b-n//lcm(a,b))*q
sum+=max(p,q)*(n//lcm(a,b))
print(sum)

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

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

n, a, b, p, q = map(int, input().split())

print(n // a * p + n // b * q - n // lcm(a, b) * min(p, q))

import math

n,a,b,p,q = [int(x) for x in input().split(' ')]

g = int(a * b / math.gcd(a,b))

if p > q: l = q
else: l = p
print((n//a)*p + (n//b)*q - (n//g)* l)

__author__ = 'aste'

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

def main():
    n, a, b, p, q = [int(x) for x in input().split()]
    div_a = n // a
    div_b = n // b
    lcm = (a*b) // gcd(a, b)
    div_ab = n // lcm

    c1 = (div_a - div_ab)*p + (div_b - div_ab)*q + div_ab*q
    c2 = (div_a - div_ab)*p + (div_b - div_ab)*q + div_ab*p

    print(max(c1, c2))

main()

import math
n,a,b,p,q=map(int, input().split())

total = p*(n//a) + q*(n//b) - (int)(min(p,q)*(n//(a*b//math.gcd(a,b))))
print(total)

from sys import stdin
input = stdin.readline
n, a, b, p, q = map(int, input().split())
from math import gcd
lcm = lambda x,y: (x * y) // gcd(x, y)
af = n // a
bf = n // b
abf = n // lcm(a, b)
ao = af - abf
bo = bf - abf
print(ao * p + bo * q + abf * (max(p, q)))

from fractions import gcd

n, a, b, p, q = map(int, input().split())
div_by_a = n // a
div_by_b = n // b
div_by_ab = n // int(a*b / gcd(a, b))

choc = div_by_a*p + div_by_b*q

if p > q:
    print(choc - div_by_ab*q)
else:
    print(choc - div_by_ab*p)

def gcd(a,b):
	if b==0:
		return a
	return gcd(b,a%b)
s=map(lambda x:int(x) , raw_input().split(' '))
n = s[0]
a = s[1]
b = s[2]
p = s[3]
q = s[4]
m=0
na=n//a
nb=n//b
nab=n//(a*b//gcd(max(a,b),min(a,b)))
if p>q:
	m=m+na*p
	m=m+(nb-nab)*q
else:
	m=m+nb*q
	m=m+(na-nab)*p
print(m)

inp = input().split()
n,a,b,p,q = int(inp[0]),int(inp[1]),int(inp[2]),int(inp[3]),int(inp[4])

t,c = a,b
r = t%c
while r!=0:
	t = c
	c = r
	r = t%c

c = (a*b)//c
ans = 0
cnt = n//c
ans += (n//c)*max(p,q)
ans += (n//a-cnt)*p
ans += (n//b-cnt)*q

print(ans)

def nok(a,b):
    n = a * b
    while a != b:
        if a > b:
            a -= b
        elif b > a:
            b -= a

    return n // a

n, a, b, p, q = list(map(int,input().split()))
nok1 = nok(a,b)
k = ((n // a) * p + (n // b) * q - (n // nok1) * (p + q)) + (n // nok1) * max(p,q)

print(k)

def lcm(a, b):
    x = a * b
    while b != 0:
        (a, b) = (b, a % b)
    return x // a

n, a, b, p, q = map(int, input().split())
print(n // a * p + n // b * q - n // lcm(a, b) * min(p, q))

import math
n, a, b, p, q=map(int, input().rstrip().split())
num_a=int(n/a)
num_b=int(n/b)
lcm=int((a*b)/math.gcd(a, b))
if lcm>n:
    print((num_a*p)+(num_b*q))
if lcm<=n:
    num_lcm=int(n/lcm)
    if p>=q:
        num_b-=num_lcm
        print((num_a*p)+(num_b*q))
    if p<q:
        num_a-=num_lcm
        print((num_a*p)+(num_b*q))

# coding: utf-8

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

line = raw_input().strip()
n, a, b, p, q = map(lambda x: int(x), line.split())

cnt_a = n / a
cnt_b = n / b
gcd = _gcd(a, b)
lcm = a * b / gcd
cnt_lcm = n / lcm

#print ">>", gcd, cnt_a, cnt_b, cnt_lcm

s = cnt_a * p + cnt_b * q
v = p if p < q else q

s -= cnt_lcm * v
print s

from fractions import gcd

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

n,a,b,q,p=map(int,input().split())
print((n//a-(n//lcm(a,b)))*q + (n//b-(n//lcm(a,b)))*p + n//(lcm(a,b))*max(p,q))

n,a,b,p,q=map(int,input().split())
if p<q: p,q,a,b=q,p,b,a
def gcd(a,b):
  while b: a,b=b,a%b
  return a
print(n//a*p+n//b*q-n//(a*b//gcd(a,b))*q)

n,a,b,p,q=map(int,input().split())
def gcd(a,b):
  while b: a,b=b,a%b
  return a
print(n//a*p+n//b*q-n//(a*b//gcd(a,b))*min(p,q))

from fractions import gcd
n,a,b,p,q=map(int,input().split())
max=max(p,q)
t=n//((a*b)//gcd(a,b))
sum=(n//a)*p +(n//b)*q -(t*min(p,q))
print(sum)

import sys

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

f = sys.stdin
n, a, b, p, q = map(int, f.readline().strip().split(' '))
x = n / a
y = n / b
z = n * gcd(a, b) / a / b
print(p * (x - z) + q * (y - z) + z * max(p, q))

# cook your dish here
import math
n, a,b ,p, q = map(int,input().split())

lcm = (a//math.gcd(a,b))*b

ans = (n//a - n//lcm)*p + (n//b - n//lcm)*q + (n//lcm)*max(p,q)

print(ans)

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

'''#4C
n = int(raw_input())
l = []
l2 = []
l3 = []
for i in range(n):
	a = raw_input()
	if a in l2:
		b=l2.index(a)
		j = l3[b]
		a += str(j)
		l3[b] += 1
	else:
		l2.append(a)
		l3.append(1)
	l.append(a)
for i in l:
	if (i[len(i)-1] in '0123456789')==0:
		print('OK')
	else:
		print(i)'''
import fractions
def LCM(a,b):return abs(a * b) / fractions.gcd(a,b) if a and b else 0

n,a,b,p,q = map(int,raw_input().split(' '))
if p<q:
	a,b,p,q = b,a,q,p
t = n//a*p
g = n//b - n//LCM(a,b)
t += g*q
print(t)

from math import floor
a,b,c,d,e = map(int, input().split())
resp = d * (floor(a // b))
resp += e * (floor(a // c))
print(resp)

#import sys
#sys.stdin = open('in', 'r')
#n = int(input())
#a = [int(x) for x in input().split()]
n,a,b,p,q = map(int, input().split())

if q > p:
    a,b = b,a
    p,q = q,p

res = (n//a)*p + (n//b)*q - (n//(a*b))*q

print(res)

n, a, b, p, q = map(int, input().split())
m = n // (a * b)
ret = (n // a - m) * p + (n // b - m) * q + m * max(p, q)
print(ret)

import fractions
n,a,b,p,q=map(int,input().split())
nok=a*b//fractions.gcd(a,b)
if a>b:
    a,b,p,q=b,a,q,p
print((n//b)*q+(n//a-n//nok)*p)

import sys;

def getGcm(a, b):
	if (b > a):
		return getGcm(b, a);
	if (0 == a % b):
		return b;
	return getGcm(b, a % b);

nums = map(int, sys.stdin.readline().split());

n = nums[0];
a = nums[1];
b = nums[2];
p = nums[3];
q = nums[4];

ab = getGcm(a, b) - 1;

a = int(n / a);
b = int(n / b);

if (p > q):
	print (a * p + (b - ab) * q);
else:
	print ((a - ab) * p + b * q);

n,a,b,p,q = map(int, input().split())
A = n//a
B = n//b
AandB = n//(a*b)
print(A*p + B*q - min(p,q)*AandB)

from math import ceil
a,b,c,d,e = map(int, input().split())
achou = False
achou2 = False
achou3 = False
primeiro3 = ultimo3 = primeiro = primeiro2 = ultimo = ultimo2 = 0
for i in range(1, a+1):
	if not achou and i % b == 0:
		primeiro = i
		achou = True
	if not achou2 and i % c == 0:
		primeiro2 = i
		achou2 = True
	if not achou3 and i % c == 0 and i % b == 0:
		primeiro3 = i
		achou3 = True
	if achou and achou2 and achou3:
		break
achou, achou2, achou3 = False, False, False
for i in range(a,0,-1):
	if not achou and i % b == 0:
		ultimo = i
		achou = True
	if not achou2 and i % c == 0:
		ultimo2 = i
		achou2 = True
	if not achou3 and i % c == 0 and i % b == 0:
		ultimo3 = i
		achou3 = True
	if achou and achou2 and achou3:
		break
if primeiro != 0 and ultimo != 0:
	resp = ((ultimo - primeiro + b) // b) * d
else: resp = 0
if primeiro2 != 0 and ultimo2 != 0:
	resp += ((ultimo2 - primeiro2 + c) // c) * e
else: resp = 0
if ultimo3 != 0 and primeiro3 != 0:
	sera = ceil((ultimo3 - primeiro3 + b + c) / 2)
else: sera = 0
print(resp - sera)

n, a, b, p, q = [int(j) for j in raw_input().split()]
print p * int(n / a) + q * int(n / b) - min(p, q) * int(n / (a * b))

n, a, b, p, q = map(int, input().split())
print(p * (n // a - n // (a * b)) + q * (n // b))

n,a,b,p,q = map(int, input().split())
both = (n//(a*b))
ans = (both)*max(p,q) + ((n//a - both) * p) + ((n//b - both) * q);
print(ans)

from fractions import gcd

n, a, b, p, q = map(int, raw_input().split())

nab = n / ((a * b) / gcd(a, b))

print ((n / a - nab) * p + (n / b - nab) * q + nab * max(p, q))*(-1**(n+1))

def pgcd(a,b):
    if a==0 or b==0:
        return a+b
    return pgcd(b,a%b)

def ppcm(a,b):
    return a*b//pgcd(a,b)

n,a,b,p,q=map(int, input().split())

N=0

if a<n or b<n:
    N=p*(n//a)+q*(n//b)-min(p,q)*(n//ppcm(a,b))

print(N)

from math import ceil
from math import floor
from math import sqrt
from math import log
import math

prime = pow(10, 9) + 7

def mod_expo(n, p, m):
	"""find (n^p)%m"""
	result = 1
	while p != 0:
		if p%2 == 1:
			result = (result * n)%m
		p //= 2
		n = (n * n)%m
	return result

def find_sequences(n):
	result = []
	if n <= 3:
		return result
	while n > 5:
		result.append("24 * 1 = 24")
		result.append(str(n) + " - " + str(n-1) + " = 1")
		n -= 2
	result.reverse()
	if n == 4:
		result.insert(0, "1 + 2 = 3")
		result.insert(1, "3 + 3 = 6")
		result.insert(2, "4 * 6 = 24")
	elif n == 5:
		result.insert(0, "1 + 4 = 5")
		result.insert(1, "5 * 5 = 25")
		result.insert(2, "25 - 3 = 22")
		result.insert(3, "22 + 2 = 24")
	return result

def check(n, k):
	v = 0
	left = n
	while left > 0:
		current = min(left, k)
		v += current
		left -= current
		left -= left//10
	return (2*v >= n)

def get_pair_count(n, arr):
	count = 0
	mp = {}
	for i in range(n):
		if arr[i] not in mp:
			mp[arr[i]] = 0
		mp[arr[i]] += 1
	for i in range(n):
		for deg in range(1, 31):
			val = pow(2, deg) - arr[i]
			if val in mp:
				count += mp[val]
				if val == arr[i]:
					count -= 1
		mp[arr[i]] -= 1

	return count

def find_bsearch(n):
	left = 1
	right = n
	middle = 0
	if n <= 2:
		return 1
	while left < right:
		#if (middle == int((left + right)/2)):
		#	right = middle
		middle = left + (right - left)//2
		#print(left, middle, right)
		if check(n, middle):
			if middle == left or not check(n, middle-1):
				return middle
			right = middle-1
		else:
			left = middle+1
	return left

def count_resistors(a, b):
	level = -1
	while b:
		cont, a = divmod(a, b)
		level += cont
		a, b = b, a
	if a == 1:
		return level+1
	return -1
def get_moves_count(n):
	s = 0
	j = 1
	for i in range(3, n+1, 2):
		s += 4*(i - 1)*j
		j += 1

	return s

def find_index(n):
	i = 2
	fibo = [0, 1]
	while(True):
		fibo.append(fibo[i-1] + fibo[i-2])
		if fibo[i] == n:
			return i-2;
		if fibo[i] > n:
			return i-3;
		i += 1

def primeFactors(n):
    # Print the number of two's that divide n
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n = n / 2

    # n must be odd at this point
    # so a skip of 2 ( i = i + 2) can be used
	for i in range(3,int(math.sqrt(n))+1,2):

        # while i divides n , print i ad divide n
		while n % i== 0:
			factors.append(i)
			n = n / i

    # Condition if n is a prime
    # number greater than 2
	if n > 2:
		factors.append(n)
	factors = set(factors)
	print(factors)

def get_ideal_playlist(n, k, songs):
	mx = 0
	pref_sum = []
	pref_sum.append(0)
	songs.sort(key = lambda x : x[1])
	for i in range(1, n+1):
		pref_sum.append(songs[i-1][0] + pref_sum[i-1])
	for i in range(1, n+1):
		current = pref_sum[min(n, i+k-1)]
		if i > 0:
			current -= pref_sum[i-1]
		current *= songs[i-1][1]
		mx = max(mx, current)
	return mx

def find_max_candies(n, a, b, p, q):
	A = n//a
	B = n//b
	C = n//(a*b)
	mx = 0
	if q >= p:
		return p*(A - C) + q*B
	return p*A + q*(B - C)

t=1
#t=int(input())
while t:
	t = t - 1
	count=0
	n, a, b, p, q = map(int, input().split())
	#n, k = map(int, input().split())
	# text = input()
	#n = int(input())
	#arr = list(map(int, input().strip().split()))[:n]
	# b = list(map(int, input().strip().split()))[:n]
	#N = input()
	# below = input()
	#n, X = map(int, input().split())
	songs = []
	#for i in range(n):
	#	l, b = map(int, input().split())
	#	songs.append((l, b))
	# print(a + g)

	print(find_max_candies(n, a, b, p, q))
	#if is_possible(n, m , x, y):
	 #	print("Chefirnemo")
	#else:
	#	print("Pofik")
	#answers = find_sequences(n)
	#if len(answers):
	#	print("YES")
	#	for answer in answers:
	#		print(answer)
	#else:
	#	print("NO")

from fractions import gcd
def lcm(x,y):
    return (x * y) // gcd(x,y)
n,a,b,p,q = map(int,raw_input().split())
g = lcm(a,b)
x = n/a
y = n/b
z = n/g
if p>=q:
    y-=z
else:
    x-=z
    print x*p + y*q

import math

inp = input().split()
n,a,b,p,q = int(inp[0]),int(inp[1]),int(inp[2]),int(inp[3]),int(inp[4])

ans = 0
c = a*b
cnt = n//c
ans += (n//c)*max(p,q)
ans += (n//a-cnt)*p
ans += (n//b-cnt)*q

print(ans)

n, a, b, p, q = map(int, raw_input().split())
ans = 0
if p > q:
	for i in range(a, n, a):
		ans += p
	for i in range(b, n, b):
		if(i % a != 0):
			ans+=q
else:
	for i in range(a, n, a):
		if(i % b != 0):
			ans+=p
	for i in range(b, n, b):
			ans+=q
print(ans)

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

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

n, a, b, p, q = map(int,input().split())
print(n//a*p+n//b*q-n//lcp(a,b)*min(p,q))

def gcd(a,b):
	a ,b = max(a,b), min(a,b)
	while (a % b != 0):
		aux = b
		b = a % b
		a = aux
	return b

N, a, b, c_a, c_b = map(int, raw_input().split())

cont = 0

n_a = N / a
n_b = N / b
if a % b == 0:
	n_ab = N / a
elif b % a == 0:
	n_ab = N /b
else :
	n_ab = N / (b *a)

n_a -= n_ab
n_b -= n_ab

cont += n_a * c_a
cont += n_b * c_b
cont += n_ab * max(c_a, c_b)

print cont

n,a,b,p,q=map(int, input().split())
result =  (n//a)*p
result += (n//b)*q
if a%b==0 or b%a == 0:
    if max(p,q) == p:
        result -= (n//max(a,b))*q
    else:
        result -= (n//max(a,b))*p
else:
    result -= (n//(a*b))*min(p,q)
print(result)

n,a,b,p,q = (int(i) for i in input().split())
print((n//a*p+n//b*q-n//(a*b)*min(p,q)))

n,a,b,p,q = list(map(int, input().strip().split()))

c = (n // a) * p + (n // b) * q - (n // (a*b)) * min(p,q)
print(c)

def main():
    from math import gcd
    n, a, b, p, q = map(int, input().split())
    if p < q:
        a, b, p, q = b, a, q, p
    print(n // a * p + (n - n * gcd(a, b) // a) // b * q)

if __name__ == '__main__':
    main()

n, a, b, p, q = map(int, input().split())
div_by_a = n // a
div_by_b = n // b
div_by_ab = n // (a*b)

choc = div_by_a*p + div_by_b*q

if p > q:
    print(choc - div_by_ab*q)
else:
    print(choc - div_by_ab*p)

import sys
n,a,b,p,q = map(int,raw_input().split())
print ((n/a)*p + (n/b)*q - (n/(a*b))*min(p,q))

n, a, b, p, q = map(int, input().split())
if (p > q): p, a, q, b = q, b, p, a
print(p * (n // a - n // (a * b)) + q * (n // b))

import math
n,a,b,p,q=map(int, input().split())

total = p*(int(n/a)) + q* (int(n/b)) - min(p,q) * (int(n/math.gcd(a,b)))
print(total)

#!/usr/bin/env python

from fractions import gcd

def lcm(a, b):
	if a%b == 0 or b%a == 0:
		return max(a,b)
	else:
		return a*b

n, a, b, p,q = [int(x) for x in raw_input().split(" ")]

chocolate_n = 0

chocolate_n += p*(n/a)
chocolate_n += q*(n/b)
chocolate_n -= min(p,q)*(n/lcm(a,b))

print chocolate_n

n,a,b,p,q=map(int,input().split())
max=max(p,q)
x,y=n//a,n//b
t=n//(a*b)
sum=0
if a%b==0 or b%a==0   :
    if a<b :
        if 2*p >q :
            sum=((x-t+1)*p) +((y-t-1)*q) +(t*max)
        else :
            sum = ((x - t)*p) + ((y - t)*q) + t * max
    else :
        if 2*q >p :
            sum=((x-t-1)*p) +((y-t+1)*q) +(t*max)
        else :
            sum = ((x - t)*p) + ((y - t)*q) + t * max
else :
    sum = ((x - t) * p) + ((y - t) * q) + t * max

print(sum)

# -*- coding: utf-8 -*-
"""
Created on Mon Jun 13 21:55:56 2016

@author: Dell_
"""

import sys
if False:
    input = open('chocolate.txt', 'r')
else:
    input = sys.stdin
x = 0
numbers = input.readline().split()

n = int(numbers[0])
a = int(numbers[1])
b = int(numbers[2])
p = int(numbers[3])
q = int(numbers[4])

chocolates = 0
numBoth = 0
numA = n//a
numB = n//b

def HCF(a,b):
    while b > 0:
        t = b
        b = a%b
        a = t
    return a

def LCM(a, b):
    lcm = (a*b) // (HCF(a,b))
    return lcm

numBoth = n // LCM(a, b)

choca = numA * p
chocb = numB * q

if choca > chocb:
    chocolates = choca + chocb - (numBoth*q)
elif choca < chocb:
    chocolates = choca + chocb - (numBoth*p)
elif choca == chocb:
    chocolates = choca + chocb - (numBoth*p)
print chocolates

def gcd(a,b) :
    while a%b>=1 and b%a>=1 :
        if a>b :
            a=a%b
        else :
            b=b%a
    if a>b :
        return b
    else :
        return a

n,a,b,p,q = map(int, input().split() )

if q>p :
    print(int(p * (n//a - n//(a*b / gcd(a,b)) ) + q * (n//b)))
else :
    print(int(p * (n//a) + q*(n//b - n//(a * b / gcd(a,b)))))

# theMonkeyKing
# CodeForces 678 C

# Euclidean GCD BitWise
def gcd( a, b ):
    while b != 0 :
        a %= b
        a ^= b
        b ^= a
    return a

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

# Taking inputs
n, a, b, p, q = map(int, raw_input().split())

# Solution
common = lcm( a, b )
red = ( n / a ) - ( n / common )
blue = ( n / b ) - ( n / common )
res = red * p + blue * q + ( n /common ) * max(p, q)

# Printing Result
print res

import math
n, a, b, p, q = map(int, input().split())
lcm = a*b/math.gcd(a, b)
ans = 0
if p >= q:
	ans = n//a*p + n//b*q - n//lcm*q
else:
	ans = n//b*q + n//a*p - n//lcm*p
print(ans)

import sys

f = sys.stdin
n, a, b, p, q = map(int, f.readline().strip().split(' '))
x = n / a
y = n / b
z = n / a / b
print(p * (x - z) + q * (y - z) + z * max(p, q))

n, a, b, p, q = map(int, input().split())
m = n // (a * b)
ret = (n // a - m) * p + (n // b - m) * q + m * max(p, q)
print(ret)

from fractions import gcd

n, a, b, p, q = map(int, raw_input().split())

nab = n / ((a * b) / gcd(a, b))

print ((n / a - nab) * p + (n / b - nab) * q + nab * max(p, q))*(-1**n)

n, a, b, p, q = map(int, input().split())

both = n//(a*b)
red  = n//a - both
blue = n//b - both

rest = 0
if max(a, b) % min(a, b) == 0:
    rest = max((red-1)*p + q, p + (blue-1)*q)
else:
    rest = red*p + blue*q

print(both*max(p, q) + rest)

def main():
    n, a, b, p, q = map(int, input().split())
    if p < q:
        a, b, p, q = b, a, q, p
    print(n // a * p + (n - n // a) // b * q)

if __name__ == '__main__':
    main()

n, a, b, p, q = map(int, raw_input().split())

divisiveisA = n / a
divisiveisB = n / b

comuns = n / (a*b)

resultado = divisiveisA * p + divisiveisB * q - comuns * (min(p,q))

print resultado

def main():
    from math import gcd
    n, a, b, p, q = map(int, input().split())
    if p < q:
        a, b, p, q = b, a, q, p
    print(n // a * p + (n - n * gcd(a, b) // a) // b * q)

if __name__ == '__main__':
    main()

n, a, b, p, q = map(int, input().split())
div_by_a = n // a
div_by_b = n // b
div_by_ab = n // (a*b)

choc = div_by_a*p + div_by_b*q

if p > q:
    print(choc - div_by_ab*q)
else:
    print(choc - div_by_ab*p)

n, a, b, p, q = [int(j) for j in raw_input().split()]
print p * int(n / a) + q * int(n / b) - min(p, q) * int(n / (a * b))

if __name__ == '__main__':
    n, a, b, p, q = map(int, input().split())

    if p < q:
        a, b = b, a
        p, q = q, p

    divisible_a = n // a
    divisible_b = n // b
    divisible_ab = n // (a * b)

    print(divisible_a * p + (divisible_b - divisible_ab) * q)

import math
n,a,b,p,q=map(int, input().split())

total = p*(n//a) + q*(n//b) - min(p,q)*(n//(a*b/math.gcd(a,b)))
print(total)

n,a,b,p,q=map(int,input().split())
if q>p: a,b=b,a; q,p=p,q
if a%b==0: print((n//a)*p+(n//b)*q-(n//a)*q)
elif b%a==0: print((n//a)*p)
else: print((n//a)*p+(n//b)*q-(n//a//b)*q)

n, a, b, p, q = map(int, input().split())

both = n//(a*b)
red  = n//a - both
blue = n//b - both

rest = 0
if max(a, b) % min(a, b) == 0 and min(a, b) != 1:
    rest = max((red-1)*p + q, p + (blue-1)*q)
else:
    rest = red*p + blue*q

print(both*max(p, q) + rest)

n, red, blue, red_cost, blue_cost = map(int, input().split())
if red%blue == 0:
    blues = n//blue - n//red
    ans = blues*blue_cost + (n//red)*max(red_cost,blue_cost)
elif blue%red == 0:
    reds = n//red - n//blue
    ans = reds*red_cost + (n//blue)*max(red_cost,blue_cost)
else:
    blues = n//blue - n//(red*blue)
    reds = n//red - n//(red*blue)
    ans = blues*blue_cost + reds*red_cost + (n//(red*blue))*max(red_cost,blue_cost)
print(ans)

def main():
    n, a, b, p, q = map(int, input().split())
    if p < q:
        a, b, p, q = b, a, q, p
    print(n // a * p + ((n - n // a) // b * q if b % a else 0))

if __name__ == '__main__':
    main()

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

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

n, a, b, p, q = map(int,input().split())
print(n//a*p+n//b*q-n//lcp(a,b)*min(p,q))

import math

inp = input().split()
n,a,b,p,q = int(inp[0]),int(inp[1]),int(inp[2]),int(inp[3]),int(inp[4])

ans = 0
c = a*b
cnt = n//c
ans += (n//c)*max(p,q)
ans += (n//a-cnt)*p
ans += (n//b-cnt)*q

print(ans)

from fractions import gcd

n, a, b, p, q = map(int, raw_input().split())

nab = n / ((a * b) / gcd(a, b))

print ((n / a - nab) * p + (n / b - nab) * q + nab * max(p, q))*(-1**(n+1))

#import sys
#sys.stdin = open('in', 'r')
#n = int(input())
#a = [int(x) for x in input().split()]
n,a,b,p,q = map(int, input().split())

if q > p:
    a,b = b,a
    p,q = q,p

res = (n//a)*p + (n//b)*q - (n//(a*b))*q

print(res)

entrada = map(int, raw_input().split())

N = entrada[0]
a = entrada[1]
b = entrada[2]
p = entrada[3]
q = entrada[4]

soma = 0
for i in range(1, N+1):
	if ((i >= a and i % a) == 0 and (i >= b and i % b == 0)):
		if (p > q):
			soma += p
		else:
			soma += q

	elif (i >= a and i % a == 0):
		soma += p
	elif (i >= b and i % b == 0):
		soma += q

print soma

def pgcd(a,b):
    if a==0 or b==0:
        return a+b
    return pgcd(b,a%b)

def ppcm(a,b):
    return a*b//pgcd(a,b)

n,a,b,p,q=map(int, input().split())

N=0

if a<n or b<n:
    N=p*(n//a)+q*(n//b)-min(p,q)*(n//ppcm(a,b))

print(N)

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

N,a,b,p,q = map(int, raw_input().split(' '))
divisao_a = N/a
divisao_b = N/b
divisao_aEb = N/((a*b)/mdc(a,b))

print (divisao_a*p) - (divisao_b*q) - (divisao_aEb*min(p,q))

n,a,b,p,q = list(map(int, input().strip().split()))

c = (n // a) * p + (n // b) * q - (n // (a*b)) * min(p,q)
print(c)

n,a,b,p,q = map(int, input().split())
both = (n//(a*b))
ans = (both)*max(p,q) + ((n//a - both) * p) + ((n//b - both) * q);
print(ans)

import fractions
n,red,blue,pred,qblue=10 ** 9,2,3,3,5
p = len(range(red, n +1, red))
q = len(range(blue, n +1, blue))
g = (red * blue) // fractions.gcd(red, blue)
inter = len(range(g, n+1, g))
if pred > qblue:
    x = p * pred
    y = (q - inter) * qblue
    print(x + y)
else:
    x = q * qblue
    y = (p - inter) * pred
    print(x + y)

n, a, b, p, q = [int(j) for j in raw_input().split()]
print p * n / a + q * n / b - min(p, q) * n / (a * b)

n,a,b,p,q=map(int, input().split())
result =  (n//a)*p
result += (n//b)*q
if a%b==0 or b%a == 0:
    if max(p,q) == p:
        result -= (n//max(a,b))*q
    else:
        result -= (n//max(a,b))*p
else:
    result -= (n//(a*b))*min(p,q)
print(result)

from fractions import gcd

n, a, b, p, q = map(int, raw_input().split())

nab = n / ((a * b) / gcd(a, b))

print ((n / a - nab) * p + (n / b - nab) * q + nab * max(p, q))*(-1**n)

n,a,b,p,q = map(int, input().split())

result = 0

dab = n//(a*b)
da = n//a
db = n//b
if max(p,q)==q:
    result += dab*q
else:
    result += dab*p

result += (da-dab)*p
result += (db-dab)*q

print(result)

n , a , b , p , q = map(int , raw_input().split())

pro  = a*b

val1 = n / a
val2 = n / b
val3 = n / pro

ans = val3 * max(p , q) + (val1 - val3)* p + (val2 - val3)*q

print ans

from fractions import *

def ppcm(a, b):
    return a * b / gcd(a, b);

n, a, b, p, q = [int(s) for s in input().split()]

if q < p:
    a, b, p, q = b, a, q, p

print(int(p * ((n//a) - (n//ppcm(a, b))) + q * (n//b)))

n, a, b, p, q = map(int, input().split())
div_by_a = n // a
div_by_b = n // b
div_by_ab = n // (a*b)

choc = div_by_a*p + div_by_b*q

if p > q:
    print(choc - div_by_ab*q)
else:
    print(choc - div_by_ab*p)

import sys

f = sys.stdin
n, a, b, p, q = map(int, f.readline().strip().split(' '))
x = n / a
y = n / b
z = n / a / b
print(p * (x - z) + q * (y - z) + z * max(p, q))

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

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

n, a, b, p, q = map(int,input().split())
print(n//a*p+n//b*q-n//lcp(a,b)*min(p,q))

n, red, blue, red_cost, blue_cost = map(int, input().split())
if red%blue == 0:
    blues = n//blue - n//red
    ans = blues*blue_cost + (n//red)*max(red_cost,blue_cost)
elif blue&red == 0:
    reds = n//red - n//blue
    ans = reds*red_cost + (n//blue)*max(red_cost,blue_cost)
else:
    blues = n//blue - n//(red*blue)
    reds = n//red - n//(red*blue)
    ans = blues*blue_cost + reds*red_cost + (n//(red*blue))*max(red_cost,blue_cost)
print(ans)

import sys

# inData = sys.argv[1:]
inData = input().split()

n, a, b, p, q = map(int, inData)

print(int(int((n / a)) * p + int((n / b)) * q - int((n / (a * b))) * (min(p, q))))

entrada = map(int,raw_input().split())
n = entrada[0]
red = entrada[1]
qtdRed = entrada[3]
blue = entrada[2]
qtdBlue = entrada[4]
saida = long(0)
if(qtdRed>=qtdBlue):
    saida += (n / red)*qtdRed
    for i in xrange(1,entrada[0]+1,blue):
        if(i % red == 0 and i % blue == 0):
            pass
        elif(i%blue == 0):
            saida += qtdBlue
else:
    saida += (n / blue)*qtdBlue
    for i in xrange(1,entrada[0]+1,red-1):
        if(i % red == 0 and i % blue == 0):
            pass
        elif(i%red == 0):
            saida += qtdRed
print saida

n,a,b,p,q=map(int,input().split())
if q>p: a,b=b,a; q,p=p,q
print((n//a)*p+(n//b)*q-(n//a//b)*q)

n, a, b, p, q = map(int, input().split())
m = n // (a * b)
ret = (n // a - m) * p + (n // b - m) * q + m * max(p, q)
print(ret)

#!/usr/bin/env python

n, a, b, p,q = [int(x) for x in raw_input().split(" ")]

chocolate_n = 0

chocolate_n += p*(n/a)
chocolate_n += q*(n/b)
# chocolate_n -= min(p,q)*(n/(a*b))

print chocolate_n

# -*- coding: utf-8 -*-
"""
Created on Mon Jun 13 21:55:56 2016

@author: Dell_
"""

import sys
if False:
    input = open('chocolate.txt', 'r')
else:
    input = sys.stdin
x = 0
numbers = input.readline().split()

n = int(numbers[0])
a = int(numbers[1])
b = int(numbers[2])
p = int(numbers[3])
q = int(numbers[4])

chocolates = 0
numBoth = 0
numA = n//a
numB = n//b

if a*b <= n:
    numBoth = n // (a*b)

choca = numA * p
chocb = numB * q

if choca > chocb:
    chocolates = choca + chocb - (numBoth*q)
elif choca < chocb:
    chocolates = choca + chocb - (numBoth*p)
elif choca == chocb:
    chocolates = choca + chocb - (numBoth*p)
print chocolates

from fractions import gcd
def lcm(a, b):
    return a*b//gcd(a, b)
n, a, b, p, q = map(int, input().split(' '))
red = n//a
blue = n//b
if (p>q):
    red -= n//lcm(a, b)
    blue += n//lcm(a, b)
else:
    red += n//lcm(a, b)
    blue -= n//lcm(a, b)

print(p*red+q*blue)

import math
n, a, b, p, q = map(int, input().split())
lcm = a*b/math.gcd(a, b)
ans = 0
if p >= q:
	ans = n//a*p + n//b*q - n//lcm*q
else:
	ans = n//b*q + n//a*p - n//lcm*p
print(ans)