#include <stdio.h>

#define MAX(x,y) (x<y)?y:x;
#define MIN(x,y) (x<y)?x:y;

long long gcd(long long a, long long b){ return b==0?a:gcd(b, a%b);}

long long lcm(long long a, long long b){ return a*(b/gcd(a,b));}

/*
long long lcm(long long a, long long b){
	int M=MAX(a,b);
	if(!(M%a)&&!(M%b)) return M;
	for(int i=(a*b)-1; i>M*2; i--){
		//printf("i %d\n" , i);
		if(!(i%a) && !(i%b)) return i;
	}
	return a*b;
	/*for(int i=M; i<=(a*b); i++){
		if(!(i%a)&&!(i%b)) return i;
	}
}*/

int main(){
	long long N, a, b, p, q;

	scanf("%llu %llu %llu %llu %llu", &N, &a, &b, &p, &q);

	long long com=lcm(a,b);
	//printf("%lld  ", com);
	if(com==-1) com=0;
	if(com) com=N/com;
	int red= N/a;
	int blue = N/b;

	if(p>q) blue-=com;
	else red-=com;

	printf("%llu\n", (red*p)+(blue*q));
	return 0;

}

#include<stdio.h>
#include<stdint.h>
int main()
{
    int64_t n,a,b,p,q,c,d,i,sum,l,s;
    while(scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q)==5){
            sum=0;
        if(p>q){
            c=n/a;
            if(a>b){
                l=a;s=b;
            }

    else{
        l=b;s=a;
    }
            sum=c*p;
            for(i=l;i<=n;i+=l){
                if(i%s==0){
                    break;
                }
            }
            d=n/b-n/i;
            sum+=d*q;
        }
    else if(p==q){
            if(a>b){
                c=n/b;
                l=a;s=b;
            }

    else{
        c=n/a;
        l=b;s=a;
    }
            sum=c*p;
            for(i=l;i<=n;i+=l){
                if(i%s==0){
                    break;
                }
            }
            d=n/l-n/i;
            sum+=d*q;
        }
        else{
            c=n/b;
            if(a>b){
                l=a;s=b;
            }

    else{
        l=b;s=a;
    }
            sum=c*q;
            for(i=l;i<=n;i+=l){
                if(i%s==0){
                    break;
                }
            }
            d=n/a-n/i;
            sum+=d*p;
        }
        printf("%I64d\n",sum);
    }

    return 0;
}

#include <stdio.h>
typedef long long int i64;
i64 min(const i64 a, const i64 b) {
    return a < b ? a : b;
}
i64 gcd(const i64 a, const i64 b) {
  return b == 0 ? a : gcd(b, a % b);
}
i64 lcm(i64 a, i64 b) {
    return a * b / gcd(a, b);
}
i64 solve(i64 n, i64 a, i64 b, i64 p, i64 q) {
    return (n / a) * p + (n / b) * q - (n / lcm(a, b)) * min(p, q);
}
int main(void) {
    int n, a, b, p, q;
    scanf("%d%d%d%d%d", &n, &a, &b, &p, &q);
    printf("%I64d", solve(n, a, b, p, q));
    return 0;
}

#include<stdio.h>

long long n,a,b,p,q;

long long m_com(long long a,long long b)
{
	long long x,y,l;
	if(a>b){
		x = a; y = b;
	}
	else{
		x = b; y = a;
	}
	l = x%y;

	while(l!=0)
	{
		x = y;
		y = l;
		l = x%y;
	}
	return a*b/y;
}

int main()
{
	while(~scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q))
	{
		long long x,y,z,m,sum=0;
		x = n/a;
		y = n/b;
		z = n/m_com(a,b);

		m = p<q?p:q;

		sum += x*p;
		sum += y*q;
		sum -= z*m;
		printf("%I64d\n",sum);
	}
}

#include<stdio.h>
long long int lcm(long long int a, long long int b);
int main(void)
{
    long long int n, a, b, p, q,i,c,common;
    while(scanf("%lld %lld %lld %lld %lld",&n, &a, &b, &p, &q)!=EOF)
    {
        c = 0;

        common = n/lcm(a,b);
        if(p>q)
            c += common*p;
        else
            c +=common*q;
        c += (n/a -common)*p;
        c += (n/b -common)*q;

        printf("%lld\n",c);
    }

    return 0;
}

long long int lcm(long long int a, long long int b)
{
    long long int x,y,r;
    x = a;
    y = b;
    while(y!=0)
    {
        r = x%y;
        x = y;
        y = r;
    }

    return (a*b)/x;
}

#include<stdio.h>
long long int gcd(long long int a,long long int b)
{
    if(b==0)    return a;
    else return gcd(b,a%b);
}
int main()
{
    long long int n,a,b,c,d,i,j,m,x,y,sum=0;
    scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&c,&d);
    m=a*b/gcd(a,b);
    x=c>d?c:d;
    y=n/m;
    sum+=(y*x);
    x=n/a;
    x-=y;
    sum+=(x*c);
    x=n/b;
    x-=y;
    sum+=(x*d);
    printf("%lld\n",sum);

    return 0;
}

#include<stdio.h>
int main()
{
          long long n,a,b,p,q;
          long long i,j,t,l,c,d,e,sum;
          scanf("%I64d",&n);
          scanf("%I64d",&a);
          scanf("%I64d",&b);
          scanf("%I64d",&p);
          scanf("%I64d",&q);
          i=a;
          j=b;
          while(j!=0)
          {
                    t=j;
                    j=i%j;
                    i=t;
          }
          l=(a*b)/i;
          c=n/a;
          d=n/b;
          e=n/l;
          if(p>=q)
          sum=(c*p)+((d-e)*q);
          else
          sum=(d*q)+((c-e)*p);
          printf("%I64d",sum);
          return 0;
}

#include <stdio.h>
long long int gcd(long long int a,long long int b)
{
    long long int c;
    while(a%b!=0)
    {
        c=b;
        b=a%b;
        a=c;
    }
    return b;
}
int main()
{
    long long int n,a,b,p,q,red,blue,total;
    scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);
    red=n/a;
    blue=n/b;
    if(a==0||b==0) total=0;
    else
    {
        total=a*b/gcd(a,b);
        total=n/total;
    }
    if(p>q) blue=blue-total;
    else red=red-total;
    total=red*p+blue*q;
    printf("%I64d",total);
    return 0;
}

#include<stdio.h>
#include<stdlib.h>

long long int n , a  ,b, p,q;

long long int max (long long int a , long long int b ){
	if (a>b) return a;
	else     return b;
}

long long int gcd(long long int a, long long int b)
{

    if(b == 0) {
            return a;
    }
    else {
        return gcd(b, a % b);
    }
}

int main () {

scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q);

long long int sum = 0 ;

long long int both = (a*b)/gcd(a,b);
both = n / both;
sum = max(p,q)* both + (n/a - both)*p + (n/b - both)*q;

printf("%lld\n",sum);
return 0;
}

#include<stdio.h>
#define ll long long int
ll gcd(ll a,ll b)
{
	if(b==0)return a;
	return gcd(b,a%b);
}
int main()
{
	ll n,a,b,p,q,na,nb,nab,temp;
	scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);
	na=n/a;
	nb=n/b;
	if(a>b)
	nab=n/((a*b)/gcd(a,b));
	else
	nab=n/((a*b)/gcd(b,a));
	if(p>q)
	printf("%lld",(na*p+nb*q-(nab*q)));
	else
	printf("%lld",(na*p+nb*q-(nab*p)));
	return 0;
}

#include <stdio.h>

long long GCD(long long a, long long b){
    long long tmp;
    if (b > a)
    {
        tmp = a;
        a = b;
        b = tmp;
    }
    if (b == 0) return a;
    return GCD(b, a % b);
}

int main(){
    long long n, a, b, p, q, x, s = 0;
    scanf("%I64d %I64d %I64d %I64d %I64d",&n, &a, &b, &p, &q);
    s += (n / a) * p;
    s += (n / b) * q;
    x = n / ((a*b)/GCD(a,b));
    if (p>q)
        s = s - (x*q);
    else
        s = s - (x*p);
    printf("%I64d",s);
    return 0;
}

#include <stdio.h>

long long int gcd(long long int a, long long int b)
{
    if (b!=0)
       return gcd(b, a%b);
    else
       return a;
}

int main(void) {
	// your code goes here
	long long int n,a,p,q,b,ans,l,numa,numb,lcm,x,y;
	scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);
	l=(n/a)*a;
	numa=(l-a)/a +1;
	ans=0;
	ans+=numa*p;
	l=(n/b)*b;
	numb=(l-b)/b +1;
	ans+=numb*q;
	lcm = ((a*b)/gcd(a,b));
	l=(n/lcm)*lcm;
	numa=(l-lcm)/lcm +1;
	if(p>q)
	ans-=numa*q;
	else ans-=numa*p;
	printf("%lld\n",ans);
	return 0;
}

#include <stdio.h>

int main()
{
    long long int n, a, b, p, q, red, blue, mixed, lcm, t, y, gcd;
    scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q);
    red = n/a;
    blue = n/b;
    y = a*b;
    while (b != 0) {
        t = b;
        b = a % b;
        a = t;
    }
    gcd = a;
    lcm = y/gcd;
    mixed = n/lcm;

    if(p > q){
        printf("%I64d",((red*p)+(blue-mixed)*q));
    }
    else {
        printf("%I64d",((blue*q)+(red-mixed)*p));
    }
    return 0;

}

#include<stdio.h>
typedef long long ll;
ll min(ll a,ll b)
{
	return a>b?b:a;
}
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}
int main()
{
    ll n,a,b,p,q;
    while(scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q)!=EOF)
    {
        ll sum=0;
        sum=(n/a)*p+(n/b)*q-min(p,q)*(n/lcm(a,b));
        printf("%I64d\n",sum);
    }
    return 0;
}

#include<stdio.h>
#include<string.h>
#include<limits.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
long long int gcd(long long int a,long long int b){
long long int x =a;
while(a){
	x=a; a=b%a; b=x;
}
return b;
}
long long int lcm(long long int a,long long int b){
	return (a*b)/gcd(a,b);
}
int main(){
long long int a,b,c,d,e;
	int cnt=0;

	scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e);

	long long int res = 0;
	long long int res1 =0;
	res= ((a/b)*d) + ( abs((a/c) - a/lcm(b,c)) * e);
	res1= ((a/c)*e) + ( abs((a/b) - a/lcm(b,c)) * d);
	res>res1?printf("%lld  ",res):printf("%lld",res1);
}

//1 2 3 4 5 6 7 8 9 10

#include<stdio.h>
#include<string.h>
#include<limits.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
long long int gcd(long long int a,long long int b){
long long int x =a;
while(a){
	x=a; a=b%a; b=x;
}
return b;
}
long long int lcm(long long int a,long long int b){
	return (a*b)/gcd(a,b);
}
int main(){
long long int a,b,c,d,e;
	int cnt=0;

	scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e);
	if(b==c){
		if(d>e){
			printf("%lld",(a/b)*d);
		}
		else printf("%lld",(a/c)*e);
		return 0;
	}

	long long int res = 0;
	long long int res1 =0;
	res= ((a/b)*d) + ( abs((a/c) - a/lcm(b,c)) * e);
	res1= ((a/c)*e) + ( abs((a/b) - a/lcm(b,c)) * d);
	res>res1?printf("%lld  ",res):printf("%lld",res1);
}

//1 2 3 4 5 6 7 8 9 10

#include <stdio.h>

int  bmm(int a, int b)
{

    if(a == 0)
        return b;
    if(a == 1)
        return 1;
    else
        bmm((a>b)?(a-b):(b-a),(a>b)?b:a);
}

int main()
{
    long long int n,a,b,p,q,na = 0,nb = 0,nab = 0,ans = 0;
    scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);

    na = n/a;
    nb = n/b;
    nab = n/((a*b) / bmm(a,b));
    na -= nab;
    nb -= nab;

    if(p > q)
    {
        ans = (na+nab)*p + nb*q;
    }
    else
    {
        ans = na*p + (nb+nab)*q;
    }
    printf("%lld",ans);
    return 0;
}

#ifdef ONLINE_JUDGE
    #define NDEBUG 1
#endif
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <math.h>

#define long int64_t
#define fore(i,k,n) for (int _k = (k), _n = (n), i = _k; i <= _n; ++i)
#define forr(i,n,k) for (int _k = (k), _n = (n), i = _n; i >= _k; --i)
#define LIST_INIT_CAP 4
#define HASH_INIT_CAP 64
#define HASH_SKIP 11
#define TREE_INIT_CAP 1024
#define TREE_MAX_HEIGHT 64
#define DEQUE_INIT_CAP 1024
#define HEAP_INIT_CAP 1024
#define TAKEN 1
#define EMPTY 0
#define TOMB -1
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))

#define N 3005

long gcd(long a, long b) {
    if (a == 0)
        return b;
    else
        return gcd(b % a, a);
}

long lcm(long a, long b) {
    return (a / gcd(a, b)) * b;
}
int main() {

    int n, a, b, p, q, pq;
    scanf("%d %d %d %d %d", &n, &a, &b, &p, &q);
    pq = max(p, q);
    long ad = n / a;
    long bd = n / b;
    long abd = (long)n / lcm(a, b);
    long answer = ((ad - abd) * p) + ((bd - abd) * q) + (abd * pq);
    printf("%I64d", answer);

    return 0;
}

#include <stdio.h>

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int main() {
	int n, a, b, p, q;
	long long both, red, blue, lcm;

	scanf("%d%d%d%d%d", &n, &a, &b, &p, &q);
	lcm = (long long) a / gcd(a, b) * b;
	both = n / lcm;
	red = n / a - both;
	blue = n / b - both;
	printf("%lld\n", red * p + blue * q + both * (p > q ? p : q));
	return 0;
}

#include<stdio.h>
long long fun(long long  i,long long  j)
{
    long a=i,b=j,l;
    while(1)
    {
        l=a%b;
        if(l)
        {
            a=b;
            b=l;
        }
        else break;
    }
    return i*j/b;
}
int main(void)
{
  long long int n,i,a,b,p,q,k,m,l,ans;

    scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);

     k=n/a;
     m=n/b;
     l=fun(a,b);
     if(p>q) m-=n/l;
     else k-=n/l;
     ans=(k*p)+(m*q);
     printf("%I64d",ans);

}

#include<stdio.h>
long long gcd(long long a, long long b)
{
        if (b == 0)
                return a;
        else
                gcd(b, a % b);
}
int main()
{
        long long i, n, a, b, p, q, sum1 = 0, sum2 = 0, sum12 = 0, lcm;
        scanf("%I64d %I64d %I64d %I64d %I64d", &n, &a, &b, &p, &q);
        lcm = a / gcd(a, b) * b;
        sum12 = n / lcm;
        sum1 = n / a - sum12;
        sum2 = n / b - sum12;
        if (p >= q)
                printf("%I64d\n", sum1 * p + sum2 * q + sum12 * p);
        else
                printf("%I64d\n", sum1 * p + sum2 * q + sum12 * q);
        return 0;
}

#include<stdio.h>

long long gcd(long long a, long long b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
int main()
{
    long long n,a,b,p,q,num1,num2,total1,total2,m;

    scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);

    if(a==b) { total1=(n/a)*p;  total2=(n/b)*q; }

    else{

    m= a/gcd(a,b);
    m=m*b;
    m=n/m;
    num1 = n/a;
    num2 =n/b;
    total1= num1 * p + (num2-m)*q;
    total2= (num1-m)*p + num2*q;

    }
    if(total1<total2) printf("%I64d\n",total2);
    else printf("%I64d\n",total1);

    return 0;
}

/* DHUOJ solution #353177 @ 2018-07-19 22:06:10.801 */

/*#include <iostream>
#include<stdio.h>
//TLE..很烦
using namespace std;

int main()
{
    //long long int result;
    int n,a,b,p,q,i;
    while(scanf("%d%d%d%d%d",&n,&a,&b,&p,&q)!=EOF)
    {
        long long int sum=0;
        //int maxpq=max(p,q);
        int max;
        if(p>q) max=p;
        else max=q;
        for(i=1;i<=n;i++)
        {
            if(i%a==0&&i%b==0){sum+=max;}
            else if(i%a==0) {sum+=p;}
            else if(i%b==0) {sum+=q;}
        }
        cout<<sum<<endl;
    }
    return 0;
}*/
#include<stdio.h>
//using namespace std;
long long int gcd(long long int a,long long int b)//貌似叫容斥原理，求a，b最大公约数
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
long long int gbs(long long int a,long long int b)//求a，b最小公倍数，数学像我一样渣的自行查资料
{
    return a*b/gcd(a,b);
}
int main()
{
   long long int n,a,b,p,q,max;
    while(scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q)!=EOF)
    {
        if(p>q) max=p;
        else max=q;
        long long sum;
        long long int n1,n2,n3;
        n1=n/a;n2=n/b;n3=n/gbs(a,b);
        sum=p*(n1-n3)+q*(n2-n3)+n3*max;
        printf("%lld\n",sum);
    }
    return 0;
}

#include<stdio.h>
int main ()
{
    long long int n,a,b,p,q,r,s,t,u,v,w,x,y,swap;
    scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);
    if(a!=b)
    {
        r=a;
        s=b;
        for(;s>0;)
        {
            swap=s;
            s=r%s;
            r=swap;
        }
        t=(a*b)/r;
        if(p>q)
        {
            u=n/a;
            v=n/b;
            w=n/t;
            x=v-w;
            y=u*p+x*q;
            printf("%lld",y);
            return 0;
        }
        if(p<=q)
        {
            u=n/a;
            v=n/b;
            w=n/t;
            x=u-w;
            y=x*p+v*q;
            printf("%lld",y);
            return 0;
        }
    }
    else
    {
        if(p>q)printf("%lld",(n/a)*p);
        if(p<=q)printf("%lld",(n/a)*q);
    }
    return 0;
}

#include <stdio.h>

long long gcd(long long m, long long n)
{
    if(n == 0) return m;
    return gcd(n, m % n);
}

int main(void) {
	// your code goes here

    long long n,a,b,p,q,lcm,ans,cnt=0;

    scanf("%lld%lld%lld%lld%lld",&n, &a, &b, &p, &q);

    lcm = a*b / gcd(a,b);

    cnt = n/lcm;

    if(p < q)
    	ans = (n/a)*p + (n/b)*q - cnt*p;
    else
    	ans = (n/a)*p + (n/b)*q - cnt*q;

	printf("%lld", ans);
}

#include <stdio.h>
long long fun(long long  m,long long  n)
{
    long a=m,b=n,k;
    while(1)
    {
        k=a%b;
        if(k)
        {
            a=b;
            b=k;
        }
        else break;
    }
    return m*n/b;
}
int main()
{
    long long n,a,b,p,q,i,j,k;
    scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q);
    i=n/a;
    j=n/b;
    k=fun(a,b);
    if(p<q)
    {
        i-=n/k;
    }
    else j-=n/k;
    printf("%I64d\n",i*p+j*q);
}

#include<stdio.h>
long long int gcd(long long int a,long long int b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
long long int lcm(long long int a,long long int b)
{
    return (a/gcd(a,b))*b;
}
int main()
{
    long long int n,a,b,p,q,t,x,y,z,m;
    scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q);

    x=n/a;
    y=n/b;
    m=lcm(a,b);
    z=n/m;
    if(p>q)
    {
        t=x*p+(y-z)*q;
        printf("%I64d\n",t);
    }
    else if(p<=q)
    {
        t=(x-z)*p+y*q;
        printf("%I64d\n",t);
    }
    return 0;

}

#include <stdio.h>
#include <stdlib.h>
typedef unsigned long long int ulli;

ulli gcd(ulli x, ulli y)
{
	if(y==0) return x;
	else return gcd(y,x%y);
}

ulli min(ulli a, ulli b)
{
	return (a<b)?a:b;
}

ulli max(ulli a, ulli b)
{
	return (a>b)?a:b;
}

ulli choc(ulli n, ulli a, ulli b, ulli p, ulli q)
{
	//if(n<a)
	//	return 0;
	ulli tiles=n,total=0;
	total+=(n/a)*p + (n/b)*q-(n/(a*b/gcd(a,b))*min(p,q));
	return total;
}

int
main (int argc, char *argv[])
{
	ulli i,n,a,b,p,q;
	scanf("%lld %lld %lld %lld %lld",&n,&a, &b, &p, &q);

	printf("%lld",choc(n,a,b,p,q) );
	return 0;
}

#include<stdio.h>
long long   gcd(long long  a1, long long  b1) { return b1? gcd(b1, a1 % b1) : a1; } //printf("нод (d, k): %d; нок (d, k): %d\n", g = gcd(d, k), d / g * k);

int main()
{ long long n,q,p,a,b;
  long long  i,res=0;
scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);
res+=(n/a)*p+(n/b)*q;

	if (a>b) i=a/gcd(a,b)*b; else i=b/gcd(a,b)*a;
	i=n/i;
	if (i>0) if (p>q) res-=q*i; else res-=p*i;
	printf("%I64d",res);

return  0;
}

#include <stdio.h>
long long int gcd (long long int a,long long int b) {
	if (b==0)
	  return a ;
	else
	  return gcd (b,a%b) ;
}
int main () {
	long long int n,a,b,p,q,i,ca=0,cb=0,cc=0 ,ans=0,lcm;
	scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q) ;
	ca=n/a ;
	cb=n/b ;
	a=a/gcd(a,b) ;
	lcm=a*b ;
	cc=n/lcm ;
	ca-=cc ;
	cb-=cc ;
	if (p>q)
	  ca+=cc ;
	else
	  cb+=cc ;
	ans=ca*p+cb*q ;
	printf("%I64d\n",ans) ;
	return 0 ;
}

#include<stdio.h>

int gcd(long long int n1,long long int n2)
{
return (n2!=0)?gcd(n2,n1%n2):n1;
}
long long lcm(long long a,long long b)
{
    return (a/gcd(a,b))*b;
}
int main()
{
long long n,a,b,p,q,ans=0;
scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);
ans+=(n/a)*p;
ans+=(n/b)*q;
ans-=(n/lcm(a,b))*(p>q?q:p);
printf("%lld\n",ans);
}

#include<stdio.h>

long long int gcd(int a,int b)
{
  long long int c;
  while ( a != 0 ) {
     c = a; a = b%a;  b = c;
  }
  return b;
}

long long int lcd(int a,int b)
{
  if(a%gcd(a,b)==0)
  return (a/gcd(a,b))*b;
  else return (b/gcd(a,b))*a;
}

int main()
{
 long long int n,a,b,p,q,red,blue,common,ans;

 scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);

 red = (n/a)-(n/lcd(a,b));
 blue = (n/b)-(n/lcd(a,b));
 common = n/lcd(a,b);

 if(p>=q) ans = red*p+blue*q+common*p;
 else ans = red*p+blue*q+common*q;

 printf("%lld\n",ans);

return 0;
}

#include<stdio.h>

int gcd(int a,int b)
{
    if(!(a%b))
        return b;
    else
        gcd(b,a%b);
}

int main()
{
    long long n,a,b,p,q,count1,count2,count3;

    scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q);

    count1=n/a;
    count2=n/b;
    count3=(n*gcd(a,b))/(a*b);

    count1=count1*p;
    count2=count2*q;
    count3=count3*(p<q?p:q);

    printf("%I64d",count1+count2-count3);

    return 0;
}

#include <stdio.h>
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b%a, a);
}
int main()
{
	//freopen("inp.txt", "r", stdin);
	long long int n,a,b,p,q;
	scanf("%lli %lli %lli %lli %lli", &n, &a, &b, &p, &q);
	//int i;
	long long int reds = 0;
	long long int blues = 0;
	reds = n/a;
	blues = n/b;
	long long int lcm = a * b / gcd(a,b);
	if(p > q)
		blues -= n/lcm;
	else
		reds -= n/lcm;
	long long int ans = reds*p + blues*q;
	printf("%lli\n", ans);
	return 0;
}

#include<stdio.h>
int main()
{
   long long int n,a,b,c,d,p,q,A,B,C,t1,t2,m1,m2,m3;
    scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);

    A = n/a;
    B = n/b;
    if(a>b)
        {
            t1=a;
            t2=b;
        }
        else
        {
            t1=b;
            t2=a;
        }
        d = hcf(t1,t2);
        c = (a*b)/d;
        C = n/c;
        A = A -C;
        B = B -C;
        m1 = A*p;
        m2 = B*q;
        if(p>q)
        {
            m3 = C*p;
        }
        else
        {
            m3 = C*q;
        }
        printf("%lld",m1+m2+m3);
        return 0;

}

      int hcf(int t1, int t2)
    {   int t;

         t = t1%t2;

         if(t1%t2==0)
            return t2;
         else
        hcf(t2,t);
    }

#include<stdio.h>
long hcf(long int a,long int b)
{
    while(a!=b)
    {
        if(a>b)
        a=a-b;
        else
        b=b-a;
    }
    return a;
}
int main()
{
    long long int n,a,b,p,q,x;
    unsigned long long int sum=0;
    scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);
    x=((long long)(a*b))/hcf(a,b);
    sum+=(long long)p*(n/a-(n/x));
    sum+=q*(n/b-(n/x));
    if(p>q)
    sum+=(long long)p*(n/x);
    else
    sum+=(long long)q*(n/x);
    printf("%I64d",sum);
}

#include<stdio.h>
int gcd(long long int a,long long int b)
{
	if(a==0) return b;
	else if(b==0) return a;
	else if(a>b) return gcd(a%b,b);
	else if(a<b) return gcd(a,b%a);
	else if(a==b) return a;
}
int main()
{
	long long int n,a,b,p,q,c,d,e,x,lcm;
	scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);
	lcm=(a*b)/gcd(a,b);
	e=n/lcm;
	if(p>q)
	{
		c=n/a;
		d=n/b-(e);
	}
	else if(p<=q)
	{
		c=n/a-(e);
		d=n/b;
	}
	x=(c*p)+(d*q);
	printf("%I64d\n",x);
}

#include <stdio.h>
#include <stdlib.h>

 long long int gcd( long long int a,  long long int b){
   /* if (a == 0 || b == 0){
        return 0;
    }if (a == b){
        return a;
    }if (a > b){
        return gcd(a-b, b);
    }else{
    return gcd(a, b-a);
    }
    */

    long long int temp;
    while (b != 0)
    {
        temp = a % b;

        a = b;
        b = temp;
    }
    return a;
}

/*

    ------
    long long int gcd;

    for(long long int i=1; i <= a && i <= b; ++i)
    {
        if(a%i==0 && b%i==0)
            gcd = i;
    }
    return gcd;
    */

/*
 utilizo la funcion gcd para obtener el greatest common divisor el cual
 será utilizado en la sig función lcm
*/

 long long int lcm( long long int a,  long long int b){
    return (a*b)/gcd(a, b);
 }

int main(){

 long long int res1, res2, max, n, a, b, p, q, na, nb, dos;

 //los hice int long long porque decía eso en codeforce

scanf("%I64d %I64d %I64d %I64d %I64d", &n, &a, &b, &p, &q);

na=n/a; //si n es divisible entre a
nb=n/b; // si n es divisible entre b

/*
if(p>q){
	min=q;
}else{
	min=p;
}
*/

dos=n/lcm(a,b);

// dos es para sacar si hay en común
//llamo a la función lcm para sacar el least common multiple
//con base en eso divido n entre su LCM de a y b, para sacar el #de divisiones en común

res1=((na-dos)*p+nb*q);
res2=((nb-dos)*q+na*p);

/*
printf("n %I64d/ lcm %I64d \n", n, lcm(a,b));
printf("na %I64d nb %I64d dos %I64d res1 %I64d res 2 %I64d\n", na, nb, dos, res1, res2);

saco aquí las dos posibles respuestas, restándole en una a na las divisiones en común
y en la otra en nb. el resto es lo mismo
*/

if(res1>res2){
	max=res1;
}else{
	max=res2;
}

/*
aquí saco la respuesta con más valor
*/

printf("%I64d\n", max);

}

#include<stdio.h>
long long gcd(long long a,long long b){
if(a%b==0) return b;
if(b%a==0) return a;
return gcd(b,a%b);
}
int main(){
long long int n,a,b,p,q;
scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);
long long int k=(n/a)*p +  (n/b)*q;
//printf("%d\n",k);
if(p>q) printf("%I64d",k-((n*gcd(a,b))/(a*b))*q);
else printf("%I64d",k-((n*gcd(a,b))/(a*b))*p);

}

#include <stdio.h>
long long int gcd(long long int a, long long int b)
{
	if(b==0)
		return a;
	else
		return gcd(b,a%b);
}

long long int lcm(long long int a, long long int b)
{
    return (a*b)/gcd(a, b);
}
int main()
{
	long long int n,a,b,p,q;
	scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);
	long long int ans;
	if(p>q)
		ans=p;
	else ans=q;
	long long int answer=p*((n/a)-(n/lcm(a,b)))+ q*((n/b)-(n/lcm(a,b)))+(n/lcm(a,b))*ans;
	printf("%lld", answer);
	return 0;

}

#include <stdio.h>
typedef long long ll;

ll gcd(ll a,ll b)
{
  //  printf("%lld %lld\n",a,b);
    if(a<b)
    {
        ll temp ;
        temp = a;
        a = b;
        b = temp;
    }
    if (b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a,b);
}

int main(int argc, char const *argv[])
{
    ll n,a,b,p,q ;
    scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);
    ll answer = 0;
    ll apart = n/a ;
    ll bpart = n/b ;
    ll dono  = lcm(a,b) ;
    ll comm = n/dono ;
    answer += (apart-comm)*p;
    answer += (bpart-comm)*q;
    if(p>q)
    {
       answer += comm*p;
    }

    else
    {
        answer += comm*q;
    }
    printf("%lld\n",answer);
  //  printf("%lld\n",gcd(27,45));
    return 0;
}

#include<stdio.h>

long long int lcm_(long long int a,long long int b){

    long long int t,l,s;
    l=a>b?a:b;
    s=a<b?a:b;
    while(s!=0){
        t=l%s;
        l=s;
        s=t;
    }
    l=(a*b)/l;
    return l;
}

int main(){
    long long int n,a,m,b,p,q,i,r,s,t;
    long long int choco=0,a_no=0,b_no=0,a_b_no=0;
    scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q);
    a_no=1+(((n/a)*a)-a)/a;
    b_no=1+(((n/b)*b)-b)/b;
    t=(p<q)?p:q;
    m=lcm_(a,b);
    a_b_no=1+(((n/m)*m)-m)/m;;
    choco=(p*a_no)+(q*b_no)-(t*a_b_no);
    printf("%lld",choco);
    return 0;
}

#include<stdio.h>
int gcd(int c,int d);
int main()
{
    long long int n,a,b,p,q,f,r,e,h,max,sum,gcd;
    while(scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q)!=EOF)
    {
       int gcd(int c,int d)
        {
            if(c==0)
        {
           return d;
        }
        else
        {
            return gcd(d%c,c);
        }
        }
        f=(a*b)/gcd(a,b);
        r=n/f;
        e=(n/a)-r;
        h=(n/b)-r;
        max=q;
        if(p>max)
        {
            max=p;
        }
        sum=(max*r)+(e*p)+(h*q);
        printf("%lld\n",sum);
    }
    return 0;
}

#include <stdio.h>

long long int gcd(long long int x, long long int y){
    if(y==0) return x;
    else return gcd(y, x%y);
}
int main()
{
    long long int n, a, b, p, q, lc, c;
    long long int na, nb, nab;

    while(scanf("%lld %lld %lld %lld %lld", &n, &a, &b, &p, &q) != EOF){
        na = n/a;
        nb = n/b;
        lc = a*b/gcd(a,b);
        nab = n/lc;
        if(p>q) nb -= nab;
        else na -= nab;
        c = na*p + nb*q;
        printf("%lld\n", c);
    }
    return 0;
}

#include<stdio.h>
#include<math.h>
int main()
{
 long long    int n,a,b,p,q,count1=0,count2=0,i,temp;
    long long int s=0;
    scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q);
   long long int d,e;
    if(a>b)
    {
        d=b;
        e=a;
        do
        {
            temp= a%b;
            a=b;
            b=temp;
        }
        while(temp!=0);
        temp=a;
        b=d;
        a=e;
    }
    else
    {
        d=a;
        e=b;
        do
        {
            temp= b%a;
            b=a;
            a=temp;
        }
        while(temp!=0);
        temp=b;
        a=d;
        b=e;
    }
    d=(a*b)/temp;
    count1=(n/a);
    count2=(n/b);
    if(p>q)
    {
        count2=count2-(n/d);
    }
    else
    {
        count1=count1-(n/d);

    }
    s=(count1*p)+(count2*q);
    printf("%I64d",s);

}

#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>

int gcd(int a, int b)
{
   if(b == 0)
   {
      return a;
   }

   return gcd(b, a % b);
}

int main()
{
   uint64_t n, a, b, p, q;
   scanf("%I64d %I64d %I64d %I64d %I64d", &n, &a, &b, &p, &q);

   uint64_t value = 0;
   value += p * (n / a);
   value += q * (n / b);
   value -= (p > q ? q : p) * (n / ((a * b) / gcd(a, b)));

   printf("%I64d\n", value);
}

#include <stdio.h>

void swap(long long* a, long long* b) {
    long long tmp = *a;
    *a = *b;
    *b = tmp;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

long long lcm(long long a, long long b) {
    return (a / gcd(a, b)) * b;
}

int main() {
    long long n, a, b, p, q;
    long long res = 0;

    scanf("%I64d%I64d%I64d%I64d%I64d", &n, &a, &b, &p, &q);
    if (p > q) {
        swap(&p, &q);
        swap(&a, &b);
    }

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

    printf("%I64d\n", res);
    return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdbool.h>

#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)

long long gcd(long long u, long long v){
    long long t;

    while (v){
        t = u;
        u = v;
        v = t % v;
    }

    if (u < 0) u = 0 - u;
    return u;
}

long long lcm(long long u, long long v){
    return (u * v) / gcd(u, v);
}

int main(){
    int i, j, k;
    long long n, a, b, p, q, x, y, z, res;

    while (scanf("%lld %lld %lld %lld %lld", &n, &a, &b, &p, &q) != EOF){
        x = n / a, y = n / b, z = n / lcm(a, b);
        res = p * (x - z) + q * (y - z);
        if (p > q) res += (p * z);
        else res += (q * z);
        printf("%lld\n", res);
    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>

long long n, a, b, p, q, s;

long long gcd(long long a, long long b) {
	return b == 0 ? a : gcd(b, a % b);
}

long long lcm(long long a,long long b) {
	return a *(b / gcd(a, b));
}
int main() {
	long long aux,c1,c2,c3;
	s = 0;
	scanf("%lld %lld %lld %lld %lld", &n, &a, &b, &p, &q);

	c1 = n / a;
	c2 = n / b;
	aux = lcm(a, b);
	c3 = n / aux;

	if (p >= q) s = c1*p + (c2 - c3)*q;
	else s = (c1 - c3)*p + c2*q;

	printf("%lld", s);

	return 0;
}
/* 1520865164910 */

#include<stdio.h>

#define DEBUG 0

long long int gcd(long long int a, long long int b) {
    return b == 0 ? a : gcd(b, a % b);
}

long long int lcm(long long int a, long long int b) {
    return a * (b / (gcd(a, b)));
}

int main() {

    long long int n, a, b, p, q;
    long long int red, blue, RnB, choc;

    scanf("%lld %lld %lld %lld %lld\n", &n, &a, &b, &p, &q);

    red = n / a;
    if(DEBUG) printf("red %lld\n", red);
    blue = n / b;
    if(DEBUG) printf("blue %lld\n", blue);
    RnB = n / lcm(a, b);
    if(DEBUG) printf("RnB %lld\n", RnB);

    red = red - RnB;
    blue = blue - RnB;

    choc = (red * p);
    if(DEBUG) printf("red * p %lld\n", choc);
    choc = choc + (blue * q);
    if(DEBUG) printf("blue * q %lld\n", choc);

    if(p >= q) {
        choc = choc + (RnB * p);
    } else {
        choc = choc + (RnB * q);
    }

    printf("%lld\n", choc);

    return 0;
}

/* 1512999929989 */

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

long long  gcd(long long  a, long long  b)
{
	return b == 0 ? a : gcd(b, a % b);
}

long long  lcm(long long  a, long long  b)
{
	return a * (b / gcd(a, b));
}

int main()
{
	long long n, a, b, p, q;

	scanf("%lld %lld %lld %lld %lld", &n, &a, &b, &p, &q);

	if (p > q)
		printf("%lld\n", (((n / a)*p) + (((n / b) - (n / lcm(a, b)))*q)));
	else
		printf("%lld\n", (((n / b)*q) + (((n / a) - (n / lcm(a, b)))*p)));

	return 0;
}

/* 1520883371712 */

#include <stdio.h>

int gcd ( int a, int b ) {
  int c;
  while ( a != 0 ) {
     c = a; a = b%a;  b = c;
  }
  return b;
}

int main() {

    long long n, a, b, p, q;
    scanf("%lld %lld %lld %lld %lld", &n, &a, &b, &p, &q);

    long long number_of_reds = n/a;
    long long number_of_blues = n/b;
    long long lcm = (a*b)/gcd(a,b);

    long long reds_or_blues = n/lcm;

    number_of_blues = number_of_blues - reds_or_blues;
    number_of_reds  = number_of_reds - reds_or_blues;
    long long g;

    if(q >= p) {
        g = q;
    }
    else {
        g = p;
    }

    long long total = number_of_blues * q + number_of_reds *p + reds_or_blues * g;

    printf("%lld\n", total);
    return 0;
}

/* 1520858414216 */

#include <stdio.h>
#include <stdlib.h>

long long int gcd(long long int a,long long int b){
    return b == 0 ? a : gcd(b,a%b);
}

long long int lcm(long long int a,long long int b) {
    return a*(b/gcd(a,b));
}

int main(){
    long long int n,a,b,p,q,i,total=0,aux,aux2;
    scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);

    if(p>q){
        aux=n/a;
        total=aux*p;
        if(b%a==0){
            printf("%lld\n",total);
            exit(0);
        }
        aux=lcm(a,b);
        aux2=n/aux;
        aux2*=q;
        aux=((n/b)*q)-aux2;
        total+=aux;
    }else
    if(q>=p){
        aux=n/b;
        total=aux*q;
        if(a%b==0){
            printf("%lld\n",total);
            exit(0);
        }
        aux=lcm(a,b);
        aux2=n/aux;
        aux2*=p;
        aux=((n/a)*p)-aux2;
        total+=aux;
    }
    printf("%lld\n",total);
}
/* 1520859454897 */

#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#include<strings.h>
#include<math.h>
#define true 1
#define false 0
#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a
//SUPERMEAT BOY
//JOTY AND CHOCOLATE
long long gcd(long long a, long long b)
{
    // base case
    if (a == 0)
        return b;
return gcd(b%a, a);
}

// Function to return LCM of two numbers
long long lcm(long long a, long long b)
{
    return (a*b)/gcd(a, b);
}

int main()
{
    long long n,a,b,p,q,mtp;
    long long  lcm(long long,long long);
    long long gcd(long long ,long long);

    scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q);
    mtp=min(p,q);
    long long l=lcm(a,b);
    printf("%I64d",p*(n/a)+q*(n/b)-(mtp*(n/l)));
    return 0;
}

#include<stdio.h>
long long int gcd(long long int a,long long int b)

{ if (b != 0)
       return gcd(b, a%b);
    else
       return a;
}
int main()
{
	long long int n,a,b,p,q;
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q);
	long long int sum=0,d,e,f,i,g;
if(a<b)
i=a;
else
i=b;

if(i>n)
printf("0\n");
else
{

f=a*b/gcd(a,b);
//printf("%lld %lld\n",g,f);
g=n/f;
if(p>q)
{
d=n/a;
e=n/b-g;
}
else
{
d=n/a-g;
e=n/b;
}
//printf("%lld %lld %lld\n",d,e,f);
sum=d*p+e*q;
printf("%lld\n",sum);
}
return 0;
}

#include <stdio.h>
int gcd(int a,int b){
	if (a==0){
		return b;
	}
	else{
		return gcd(b%a,a);
	}
}
int main()
{
	long long int n,m,a,b,c,maxi,r,e,f,h;
	scanf("%lld %lld %lld %lld %lld",&a,&n,&m,&b,&c);
	f=(n*m)/gcd(n,m);
	r=a/f;
	e=(a/n)-r;
	h=(a/m)-r;
	maxi=b;
	if (c>maxi){
		maxi=c;
	}
	printf("%lld",maxi*r+e*b+h*c);
	return 0;
}

#include <stdio.h>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <limits.h>
#define offset(t,m) ((unsigned long)&(((t*)0)->m))
#define container_of(a,t,m) ((t*)((unsigned long)a-offset(t,m)))
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define SWP(a, b) if ((a) != (b)) do {(a) ^= (b); (b) ^= (a); (a) ^= (b);} while(0)
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define max(x,y) ((x) < (y) ? (y) : (x))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#endif
#ifndef _WCC_NUMTH_H
#define _WCC_NUMTH_H
#include <assert.h>
#define NUMTH_ENS (-1)
#define NUMTH_MODPLS(x, y, p) ((((x) % (p)) + ((y) % (p))) % p)
#define NUMTH_MODMUL(x, y, p) ((((X) % (P)) * ((y) % (p))) % p)
#define NUMTH_CORRECT(x, mod) ((x) += ((x) < 0 ? (mod) : 0))
long long numth_modexp(long long a, long long b, long long n);
long long numth_gcd(long long a, long long b);
void numth_gcd_e(long long a, long long b, long long *d, long long *x, long long *y);
int numth_mle(long long a, long long b, long long n, long long *x, long long *gcd);
#define numth_for_each_solution(i, x, n, d) \
	for ((i) = 0; (i) < (d); (i) += 1, (x) = ((x) + (n) / (d)) % (n))
int numth_divisors(long long k, long long divs[], long long *ndivs);
#endif
int main(void)
{
	long long n, a, b, p, q;
	long long lcm;
	scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &p, &q);
	lcm = a / numth_gcd(a, b) * b;
	printf("%lld\n", (n / a) * p + (n / b) * q - n / lcm * min(p, q));
	return 0;
}
static long long numth_do_gcd(long long a, long long b);
static void numth_do_gcd_e(long long grt, long long les, long long *d, long long *x, long long *y);
long long numth_modexp(long long a, long long b, long long n)
{
	static long long bit63 = (unsigned long long)0x8000000000000000;
	long long square = 1;
	int i;
	assert(b >= 0 && n > 0);
	for(i = 63; i >= 0 && (b & bit63) == 0; --i)
		b <<= 1;
	for(; i >= 0; --i) {
		square = (square * square) % n;
		if (b & bit63)
			square = (square * a) % n;
		b <<= 1;
	}
	return square;
}
long long numth_gcd(long long a, long long b)
{
	if (a == 0 && b == 0)
		return 0;
	if (a < 0)
		a *= -1;
	if (b < 0)
		b *= -1;
	return numth_do_gcd(a, b);
}
static long long numth_do_gcd(long long a, long long b)
{
	long long r;
	if (!b)
		return a;
	for (r = a % b; r != 0; r = a % b) {
		a = b;
		b = r;
	}
	return b;
}
void numth_gcd_e(long long a, long long b, long long *d, long long *x, long long *y)
{
	if (a == 0 && b == 0) {
		*d = *x = *y = 0;
		return;
	}
	if (a < 0)
		a *= -1;
	if (b < 0)
		b *= -1;
	if (a < b)
		numth_do_gcd_e(b, a, d, y, x);
	else
		numth_do_gcd_e(a, b, d, x, y);
}
static void numth_do_gcd_e(long long a, long long b, long long *d, long long *x, long long *y)
{
	long long tmp;
	if (b == 0) {
		*d = a;
		*x = 1;
		*y = 0;
		return;
	}
	numth_do_gcd_e(b, a % b, d, x, y);
	tmp = *x;
	*x = *y;
	*y = (tmp - (a / b) * (*y));
}
int numth_mle(long long a, long long b, long long n, long long *solution, long long *gcd)
{
	long long d, x, y;
	assert(n != 0);
	if (n < 0)
		n *= (-1);
	if (a < 0)
		a *= (-1);
	if (b < 0)
		b *= (-1);
	numth_gcd_e(a, n, &d, &x, &y);
	assert(d != 0);
	if (b % d)
		return NUMTH_ENS;
	*solution = ((b / d) * (x % n)) % n;
	NUMTH_CORRECT(*solution, n);
	*gcd = d;
	return 0;
}
int numth_divisors(long long k, long long divs[], long long *ndivs)
{
	long long i, n;
	assert(k > 0);
	n = 0;
	for (i = 1; i * i < k; ++i)
		if (k % i == 0)
			divs[n++] = i;
	if (i * i == k) {
		divs[n++] = i;
		i = n - 2;
	} else {
		i = n - 1;
	}
	for (; i >= 0; --i)
		divs[n++] = k / divs[i];
	*ndivs = n;
	return 0;
}

#include<stdio.h>
int GCD(int a,int b)
{
    int t;
    for(;;)
        {
            if(b==0)
            return a;
            t=a%b;
            a=b;
            b=t;
        }
}
int main()
{
    long long n,a,b,p,q,max,min,k,l,i,j;
    scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);
    max=p>q ?p:q;
    min=p+q-max;
    //printf("%lld",max);
    if(max==p)
    {
           k=GCD(a,b);
           k=(a*b)/k;
           l=n/k;
           i=n/b;
           i=i-l;
           j=n/a;
           k=i*q+j*p;
    }
    else
    {
           k=GCD(a,b);
           k=(a*b)/k;
           l=n/k;
           i=n/a;
           i=i-l;
           j=n/b;
           k=i*p+j*q;
    }
    printf("%lld",k);
}

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <math.h>

int64_t gcd(int a, int b)
{
        int temp;
        while (b != 0)
        {
                temp = a % b;

                a = b;
                b = temp;
        }
        return a;
}

int main()
{
        int64_t n, a, b, p, q, s;
        while (scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &p, &q) > 0) {
                int64_t i = 1;
                s = 0;
                s += (n / a) * p;
                s += (n / b) * q;
                s -= (n / ((a * b)/gcd(a, b))) * (p > q ? q : p);
                printf("%lld\n", s);
        }
}

#include<stdio.h>
int main()
{
    int n,a,b,p,q,a1,b1,ab,c=0,temp;
    long long ans,lcm,m;
    scanf("%d%d%d%d%d",&n,&a,&b,&p,&q);
    a1=n/a;
    b1=n/b;
    m=1ll*a*b;
    while(a&&b)
    {
        temp=b%a;
        b=a;
        a=temp;
    }
    lcm=m/b;
    ab=n/lcm;
    //printf("%d\n",lcm);
    if(p>q)
    {
        b1=b1-ab;
    }
    else
    {
        a1=a1-ab;
    }
    ans=1LL*p*a1+1LL*q*b1;
    printf("%lld",ans);
    return 0;
}

#include<stdio.h>

unsigned long long gcdnum(unsigned long long int a,unsigned long long int b){

    while( b!=0 ){
        a %= b;
        if( a==0 ) return b;
        b %= a;
    }
    return a;
}

unsigned long long lcmnum(unsigned long long int a,unsigned long long int b ){
unsigned long long int temp=a;
if(a>b){
a=b;
b=temp;
}
temp=b;
while(1)
    {
        if( temp%a==0)
        {
            return temp;
        }
        temp+=b;
    }
}
int main(){
unsigned long long int n,a,b,p,q;
scanf("%llu %llu %llu %llu %llu",&n,&a,&b,&p,&q);
unsigned long long int gcd = gcdnum(a,b);
unsigned long long int total=0;
unsigned long long int lcm=(a*b)/gcd;
total+=(n/a)*p;
total+=(n/b)*q;
if(p>q){
total-=(n/lcm)*q;
}
else total-=(n/lcm)*p;

printf("%llu\n",total);

}

#include<stdio.h>
int gcd(long long a,long long b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}

main()
{
    long long int n,a,b,p,q,x,y,z,l;
    scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);
    l=a*b/gcd(a,b);
    z=n/l;
    if(p<q)
        x=((n/a)*p)+((n/b)*q)-(p*z);
    else
         x=((n/a)*p)+((n/b)*q)-(q*z);
    printf("%I64d",x);
}

#include <stdio.h>

int main()
{
    long long int n, a, b, p, q, red, blue, mixed, lcm, t, y, gcd;
    scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q);
    red = n/a;
    blue = n/b;
    y = a*b;
    while (b != 0) {
        t = b;
        b = a % b;
        a = t;
    }
    gcd = a;
    lcm = y/gcd;
    mixed = n/lcm;

    if(p > q){
        printf("%I64d",((red*p)+(blue-mixed)*q));
    }
    else {
        printf("%I64d",((blue*q)+(red-mixed)*p));
    }
    return 0;

}

#include<stdio.h>
long long int gcd(long long int a,long long int b)
{
	if(b==0)
	{
		return a;
	}
	else
	{
		gcd(b,a%b);
	}
}
int main()
{
	long long int n,a,b,p,q,lcm,gcd1,max,sum,nl,na,nb;
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q);
	gcd1= gcd(a,b);
//	printf("gcd id %lld\n",gcd1);
	lcm= (a*b)/gcd1;
	if(p>=q)
	{
		max=p;
	}
	else
	{
		max=q;
	}
	nl= n/lcm;
	na= (n/a)-nl;
	nb= (n/b)-nl;
	sum= (na*p)+(nb*q)+(nl*max);
	printf("%lld\n",sum);
	return 0;
}

#include<stdio.h>
typedef long long int ll;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll lcm(ll a,ll b)
{
    return (a*b)/gcd(a, b);
}
int main()
{
    ll n,a,b,p,q,l1,l2,c; scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q);
    l1=n/a; l2=n/b;
    long long l=lcm(a,b);
    c=n/l;
    if(q>p) l1-=c;
    else l2-=c;
    long long int res=(l1*p)+(l2*q);
    printf("%lld\n",res);
    return 0;
}

#include <stdio.h>
#include <stdint.h>

typedef long long ll;

// function to calculate gcd
// or hcf of two numbers.
ll gcd(ll a, ll b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

// function to calculate
// lcm of two numbers.
ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

int main(){

	ll n,a,b,p,q;
	scanf("%lli %lli %lli %lli %lli",&n,&a,&b,&p,&q);

	//multiples of the first one
	const ll ma = n/a;
	const ll mb = n/b;
	const ll both = n/lcm(a,b);

	//optimize for reward
	ll best = 0;
	if(p > q) {
		//prefer ma, get the excluisve b
		const ll exb = mb - both;
		best = ma*p+exb*q;
	} else {
		const ll exa = ma - both;
		best = mb*q+exa*p;
	}

	printf("%lli",best);

	return 0;
}

#include<stdio.h>
long long int gongbeishu(long long int a,long long int b){
	long long int t,aa=a,bb=b;
	if(a<b){
		t=a;a=b;b=t;
	}
	while(a%b!=0){
		t=a%b;
		a=b;
		b=t;
	}
	return aa*bb/b;
}
int main(){
	long long int i,n,a,b,p,q;
	long long int ans;
	while(~scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q)){
		ans=0;
		if(q>=p){
			ans+=n/b*q;
			if(a!=b){
				ans+=n/a*p;
				i=gongbeishu(a,b);
				ans-=n/i*p;
			}
		}
		else{
			ans+=n/a*p;
			if(a!=b){
				ans+=n/b*q;
				i=gongbeishu(a,b);
				ans-=n/i*q;
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}

#include <stdio.h>
long long lcm(long long a,long long b)
{
    if(b==0)return a;
    else return  lcm(b,a%b);
}
int main()
{
    long long n,a,b,p,q,m;
    long long ans;
    while(scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q)!=EOF)
    {m=a*b/lcm(a,b);
        if(p>q)
        ans=(n/a)*p+(n/b)*q-(n/m)*q;
        else  ans=(n/a)*p+(n/b)*q-(n/m)*p;
        printf("%I64d\n",ans);
    }
}

#include<stdio.h>
// C program to find LCM of two numbers
#include <stdio.h>

// Recursive function to return gcd of a and b
long long int gcd(long long int a, long long int b)
{
    // Everything divides 0
    if(b == 0)
	    return a;
    return gcd(b,a%b);
}

// Function to return LCM of two numbers
long long int lcm(long long int a, long long int b)
{
    return (a*b)/gcd(a, b);
}
int main()
{
	long long int n,a,b,p,q,ans;
	scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);
	long long int i,x=0,y=0,z,e;
	/*
	for(i=1;i<=n;i++)
	{
		if((i%a==0)&&(i%b!=0))
		{
			x++;
		}
		if((i%b==0)&&(i%a!=0))
		{
			y++;
		}
		if((i%a==0)&&(i%b==0))
		{
			if(p<q)
				y++;
			else
				x++;
		}
	}
	printf("%lld\n",(p*x+q*y));
	*/
	x=n/a;
	y=n/b;
	e=lcm(a,b);
	z=n/e;
	x=x-z;
	y=y-z;
	ans=p*x+q*y;
	if(p<q)
		ans=ans+z*q;
	else
		ans=ans+z*p;
	printf("%lld\n",ans);
}

#include<stdio.h>
#define m 1000000010
int main()
{
	long long int n,a,b,p,q,c,d,e,x;
	scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);
	e=n/(a*b);
	if(p>q)
	{
		c=n/a;
		d=n/b-(e);
	}
	else if(p<=q)
	{
		c=n/a-(e);
		d=n/b;
	}
	x=(c*p)+(d*q);
	printf("%I64d\n",x);
}

#include<stdio.h>
int main()
{
	long long int n,a,b,p,q,c,d,e,x;
	scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);
	if(n<(a*b)) e=1;
	else e=n/(a*b);
	if(p>q)
	{
		c=n/a;
		d=n/b-(e);
	}
	else if(p<=q)
	{
		c=n/a-(e);
		d=n/b;
	}
	x=(c*p)+(d*q);
	printf("%I64d\n",x);
}

#include <stdio.h>
#include <stdlib.h>

int gcd(int a, int b){
    if (a == 0 || b == 0){
        return 0;
    }if (a == b){
        return a;
    }if (a > b){
        return gcd(a-b, b);
    }else{
    return gcd(a, b-a);
    }
 }

 /*
 utilizo la funcion gcd para obtener el greatest common divisor el cual
 será utilizado en la sig función lcm
 */

  int lcm(int a, int b){
    return (a*b)/gcd(a, b);
 }

int main(){

int long long res1, res2, max; //los hice int long long porque decía eso en codeforces
int n, a, b, p, q, na, nb, mcm, min, dos;

scanf("%i %i %i %i %i", &n, &a, &b, &p, &q);

na=n/a; //si n es divisible entre a
nb=n/b; // si n es divisible entre b

/*if(p>q){
	min=q;
}else{
	min=p;
}*/

dos=n/lcm(a,b);
// dos es para sacar si hay en común
//llamo a la función lcm para sacar el least common multiple
//con base en eso divido n entre su LCM de a y b, para sacar el #de divisiones en común

res1=((na-dos)*p+nb*q);
res2=((nb-dos)*q+na*p);
/*
saco aquí las dos posibles respuestas, restándole en una a na las divisiones en común
y en la otra en nb. el resto es lo mismo
*/

if(res1>res2){
	max=res1;
}else{
	max=res2;
}

/*
aquí saco la respuesta con más valor
*/

printf("%I64d", max);

}

#include <stdio.h>
#include <stdlib.h>

int gcd(int a, int b){
    if (a == 0 || b == 0){
        return 0;
    }if (a == b){
        return a;
    }if (a > b){
        return gcd(a-b, b);
    }else{
    return gcd(a, b-a);
    }
 }

 /*
 utilizo la funcion gcd para obtener el greatest common divisor el cual
 será utilizado en la sig función lcm
 */

  int lcm(int a, int b){
    return (a*b)/gcd(a, b);
 }

int main(){

int long long res1, res2, max, n, a, b, p, q, na, nb, min, dos;//los hice int long long porque decía eso en codeforce

scanf("%I64d %I64d %I64d %I64d %I64d", &n, &a, &b, &p, &q);

na=n/a; //si n es divisible entre a
nb=n/b; // si n es divisible entre b

/*if(p>q){
	min=q;
}else{
	min=p;
}*/

dos=n/lcm(a,b);
// dos es para sacar si hay en común
//llamo a la función lcm para sacar el least common multiple
//con base en eso divido n entre su LCM de a y b, para sacar el #de divisiones en común

res1=((na-dos)*p+nb*q);
res2=((nb-dos)*q+na*p);
/*
saco aquí las dos posibles respuestas, restándole en una a na las divisiones en común
y en la otra en nb. el resto es lo mismo
*/

if(res1>res2){
	max=res1;
}else{
	max=res2;
}

/*
aquí saco la respuesta con más valor
*/

printf("%I64d", max);

}

#include <stdio.h>
#include <stdlib.h>

int gcd(int a, int b){
    if (a == 0 || b == 0){
        return 0;
    }if (a == b){
        return a;
    }if (a > b){
        return gcd(a-b, b);
    }else{
    return gcd(a, b-a);
    }
 }

 /*
 utilizo la funcion gcd para obtener el greatest common divisor el cual
 será utilizado en la sig función lcm
 */

  int lcm(int a, int b){
    return (a*b)/gcd(a, b);
 }

int main(){

int long long res1, res2, max, n, a, b, p, q, na, nb, mcm, min, dos;//los hice int long long porque decía eso en codeforce

scanf("%I64d %I64d %I64d %I64d %I64d", &n, &a, &b, &p, &q);

na=n/a; //si n es divisible entre a
nb=n/b; // si n es divisible entre b

/*if(p>q){
	min=q;
}else{
	min=p;
}*/

dos=n/lcm(a,b);
// dos es para sacar si hay en común
//llamo a la función lcm para sacar el least common multiple
//con base en eso divido n entre su LCM de a y b, para sacar el #de divisiones en común

res1=((na-dos)*p+nb*q);
res2=((nb-dos)*q+na*p);
/*
saco aquí las dos posibles respuestas, restándole en una a na las divisiones en común
y en la otra en nb. el resto es lo mismo
*/

if(res1>res2){
	max=res1;
}else{
	max=res2;
}

/*
aquí saco la respuesta con más valor
*/

printf("%I64d", max);

}

#include<stdio.h>
long long gcd(long long a,long long b){
if(a%b==0) return b;
if(b%a==0) return a;
return gcd(b,a%b);
}
int main(){
long long int n,a,b,p,q;
scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);
long long int k=(n/a)*p +  (n/b)*q;
//printf("%d\n",k);
if(p>q) printf("%I64d",k-((n*gcd(a,b))/(a*b))*q);
else printf("%I64d",k-(n/(a*b))*p);

}

#include<stdio.h>
int main(){
long long int n,a,b,p,q;
scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);
long long int k=(n/a)*p +  (n/b)*q;
//printf("%d\n",k);
if(p>q) printf("%I64d",k-(n/(a*b))*q);
else printf("%I64d",k-(n/(a*b))*p);

}

#include<stdio.h>
int main(){
int n,a,b,p,q;
scanf("%d %d %d %d %d",&n,&a,&b,&p,&q);
int k=(n/a)*p +  (n/b)*q;
//printf("%d\n",k);
if(p>q) printf("%d",k-(n/(a*b))*q);
else printf("%d",k-(n/(a*b))*p);

}

#include <stdio.h>
int main()
{
	long long int n,a,b,p,q;
	scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);
	long long int ans;
	if(p>q)
		ans=p;
	else ans=q;
	long long int answer=p*((n/a)-(n/(a*b)))+ q*((n/b)-(n/(a*b)))+(n/(a*b))*ans;
	printf("%lld", answer);
	return 0;

}

#include <stdio.h>
typedef long long ll;

int main(int argc, char const *argv[])
{
    ll n,a,b,p,q ;
    scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);
    ll answer = 0;
    ll apart = n/a ;
    ll bpart = n/b ;
    ll comm  = a*b ;
    comm = n/comm ;
    answer += (apart-comm)*p;
    answer += (bpart-comm)*q;
    if(p>q)
    {
       answer += comm*p;
    }

    else
    {
        answer += comm*q;
    }
    printf("%lld\n",answer);

    return 0;
}

#include<stdio.h>
int main()
{
    int n,a,b,p,q,a1,b1,ab,c=0;
    long long ans;
    scanf("%d%d%d%d%d",&n,&a,&b,&p,&q);
    a1=n/a;
    b1=n/b;
    ab=n/(a*b);
    if(n<a*b&&n%a==0&n%b==0)
        c++;
    if(p>q)
    {
        b1=b1-ab-c;
    }
    else
    {
        a1=a1-ab-c;
    }
    ans=1LL*(1LL*p*a1+1LL*q*b1);
    printf("%lld",ans);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,a,b,p,q,a1,b1,ab;
    long long ans;
    scanf("%d%d%d%d%d",&n,&a,&b,&p,&q);
    a1=n/a;
    b1=n/b;
    ab=n/(a*b);
    if(p>q)
    {
        b1=b1-ab;
    }
    else
    {
        a1=a1-ab;
    }
    ans=1LL*(1LL*p*a1+1LL*q*b1);
    printf("%lld",ans);
    return 0;
}

#include<stdio.h>
int main()
{
    int n,a,b,p,q,a1,b1,ab,c=0,temp,lcm,m;
    long long ans;
    scanf("%d%d%d%d%d",&n,&a,&b,&p,&q);
    a1=n/a;
    b1=n/b;
    m=a*b;
    while(a&&b)
    {
        temp=b%a;
        b=a;
        a=temp;
    }
    lcm=m/b;
    ab=n/lcm;
    if(p>q)
    {
        b1=b1-ab;
    }
    else
    {
        a1=a1-ab;
    }
    ans=1LL*p*a1+1LL*q*b1;
    printf("%lld",ans);
    return 0;
}

#include<stdio.h>
main()
{
    long long int n,a,b,p,q,x,y,z;
    scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);
    x=n/a;
    y=n/b;
    z=(x*p)+(y*q);
    printf("%I64d",z);
}

#include<stdio.h>
int gcd(long long a,long long b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}

main()
{
    long long int n,a,b,p,q,x,y,z,l;
    scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);
    l=a*b/gcd(a,b);
    z=n/l;
    if(p<q)
        x=((n*p)/a)+((n*q)/b)-(p*z);
    else
         x=((n*p)/a)+((n*q)/b)-(q*z);
    printf("%I64d",x);
}

#include<stdio.h>
int gcd(long long a,long long b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}

main()
{
    long long int n,a,b,p,q,x,y,z,l;
    scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);
    l=a*b/gcd(a,b);
    z=n/l;
    if(p<q)
        x=(n*p/a)+(n*q/b)-(p*z);
    else
         x=(n*p/a)+(n*q/b)-(q*z);
    printf("%I64d",x);
}

#include<stdio.h>
int gcd(int a, int b)
{
    if (a == 0 || b == 0)
        return 0;
    if (a == b)
        return a;
    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}
int lcm(int a, int b)
{
    return (a*b)/gcd(a, b);
}
int main()
{
    int n,a,b,p,q,l1,l2,l,c; scanf("%d%d%d%d%d",&n,&a,&b,&p,&q);
    l1=n/a; l2=n/b;
    l=lcm(a,b);
    c=n/l;
    if(q>p) l1-=c;
    else l2-=c;
    long long int res=(l1*p)+(l2*q);
    printf("%lld\n",res);
    return 0;
}

#include <stdio.h>
int main()
{
    long long n,a,b,p,q,m;
    long long ans;
    while(scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q)!=EOF)
    {if(p>q)m=p;
    else m=q;
        ans=(n/a)*p+(n/b)*q-(n/(a*b))*m;
        printf("%lld\n",ans);
    }
}

#include <stdio.h>
int main()
{
    long long n,a,b,p,q,m;
    long long ans;
    while(scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q)!=EOF)
    {if(p>q)
        ans=(n/a)*p+(n/b)*q-(n/(a*b))*q;
        else  ans=(n/a)*p+(n/b)*q-(n/(a*b))*p;
        printf("%I64d\n",ans);
    }
}

#include <stdio.h>
int main()
{
    long long n,a,b,p,q,m;
    long long ans;
    while(scanf("%l64d%l64d%l64d%l64d%l64d",&n,&a,&b,&p,&q)!=EOF)
    {if(p>q)
        ans=(n/a)*p+(n/b)*q-(n/(a*b))*q;
        else  ans=(n/a)*p+(n/b)*q-(n/(a*b))*p;
        printf("%l64d\n",ans);
    }
}

#include <stdio.h>
typedef long long int i64;
i64 min(const i64 a, const i64 b) {
    return a < b ? a : b;
}
i64 gcd(const i64 a, const i64 b) {
  return b == 0 ? a : gcd(b, a % b);
}
i64 lcm(i64 a, i64 b) {
    return a * b / gcd(a, b);
}
i64 solve(i64 n, i64 a, i64 b, i64 p, i64 q) {
    return (n / a) * p + (n / b) * q - (n / lcm(a, b)) * min(p, q);
}
int main(void) {
    int n, a, b, p, q;
    scanf("%d%d%d%d%d", &n, &a, &b, &p, &q);
    printf("%d", solve(n, a, b, p, q));
    return 0;
}

#include <stdio.h>
typedef long long int i64;
i64 min(const i64 a, const i64 b) {
    return a < b ? a : b;
}
i64 gcd(i64 a, i64 b) {
    return b == 0 ? a : gcd(a, a % b);
}
i64 lcm(i64 a, i64 b) {
    return a * b / gcd(a, b);
}
i64 solve(i64 n, i64 a, i64 b, i64 p, i64 q) {
    return (n / a) * p + (n / b) * q - (n / lcm(a, b)) * min(p, q);
}
int main(void) {
    int n, a, b, p, q;
    scanf("%d%d%d%d%d", &n, &a, &b, &p, &q);
    printf("%d", solve(n, a, b, p, q));
    return 0;
}

#include <stdio.h>
typedef long long int i64;
i64 min(const i64 a, const i64 b) {
    return a < b ? a : b;
}
i64 gcd(i64 a, i64 b) {
    return b == 0 ? a : gcd(a, a % b);
}
i64 lcm(i64 a, i64 b) {
    return a * b / gcd(a, b);
}
i64 solve(i64 n, i64 a, i64 b, i64 p, i64 q) {
    return (n / a) * p + (n / b) * q - n / lcm(a, b) * min(p, q);
}
int main(void) {
    int n, a, b, p, q;
    scanf("%d%d%d%d%d", &n, &a, &b, &p, &q);
    printf("%d", solve(n, a, b, p, q));
    return 0;
}

#include<stdio.h>
int main(void)
{
    long long int n, a, b, p, q,i,c,common;
    while(scanf("%lld %lld %lld %lld %lld",&n, &a, &b, &p, &q)!=EOF)
    {
        c = 0;

        common = n/(a*b);
        if(p>q)
            c += common*p;
        else
            c +=common*q;
        c += (n/a -common)*p;
        c += (n/b -common)*q;

        printf("%lld\n",c);
    }

    return 0;
}

#include<stdio.h>
int main()
{
          long long n,a,b,p,q,i,j,c,d,e,t,lcm,sum;
          scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);
          i=p;
          j=q;
          while(j!=0)
          {
                    t=j;
                    j=i%j;
                    i=t;
          }
          lcm=(p*q)/i;
          c=n/a;
          d=n/b;
          e=n/lcm;
          if(p>=q)
          {
                    sum=(c*p)+(d-e)*q;
          }
          else
          {
                    sum=(d*q)+(c-e)*p;
          }
          printf("%I64d",sum);
          return 0;
}

#include <stdio.h>
int main()
{
    long long int n,a,b,p,q,red,blue,total;
    scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);
    red=n/a;
    blue=n/b;
    total=a*b;
    total=n/total;
    if(p>q) blue=blue-total;
    else red=red-total;
    total=red*p+blue*q;
    printf("%I64d",total);
    return 0;
}

#include <stdio.h>

int main()
{
    long long int n, a, b, p, q, red, blue, mixed;
    scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q);
    mixed = n/(a*b);
    red = n/a;
    blue = n/b;
    if(p > q){
        printf("%I64d",((red*p)+(blue-mixed)*p));
    }
    else {
        printf("%I64d",((blue*q)+(red-mixed)*p));
    }
    return 0;

}

#include<stdio.h>
int main()
{
	__int64 n,a,b,p,q;
	while(scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q)!=EOF)
	{
		double sum=0;
		sum+=n/a*p;
		sum+=n/b*q;
		__int64 m=a,nn=b,c=m%nn;
		while(c!=0)
		{
			__int64 t=m%nn;
			m=nn;
			nn=t;
			c=m%nn;
		}
	    __int64 k=a*b/nn;
		sum-=n/k*(p<q?p:q);
		printf("%.0lf\n",sum);
	}
	return 0;
}

#include<stdio.h>
typedef long long ll;
ll min(ll a,ll b)
{
	return a>b?b:a;
}
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}

ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

int main()
{
    ll n,a,b,p,q;
    while(scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q)!=EOF)
    {
        ll sum=0;
        sum=(n/a)*p+(n/b)*q-min(p,q)*(n/lcm(a,b));
        printf("%I64%d\n",sum);
    }
    return 0;
}

#include<stdio.h>
int main()
{
	__int64 n,a,b,p,q;
	while(scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q)!=EOF)
	{
		double sum=0;
		sum+=n/a*p;
		sum+=n/b*q;
		__int64 m=a,nn=b,c=m%nn;
		while(c!=0)
		{
			__int64 t=m%nn;
			m=nn;
			nn=t;
			c=m%nn;
		}
	    __int64 k=a*b/nn;
		sum-=n/k*(p<q?p:q);
		printf("%.0f\n",sum);
	}
	return 0;
}

#include<stdio.h>
#include<string.h>
#include<limits.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
long long int gcd(long long int a,long long int b){
	if(a==1)
		return b;
	return(a,b%a);
}
long long int max(long long int a,long long int b){
	return a>b?a:b;
}
int main(){
	long long int a,b,c,d,e;
	int cnt=0;

	scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e);
	if(b==c){
		if(d>e){
			printf("%lld",(a/b)*d);
		}
		else printf("%lld",(a/c)*e);
		return 0;
	}

	long long int res = 0;
	long long int res1 =0;
	res= ((a/b)*d) + ( max(((a/b+a/c)-(a/(b*c))-a/b),0 ) * e);
	res1= ((a/c)*e) + ( max(((a/b+a/c)-(a/(b*c)) - a/c),0 ) * d);
	res>res1?printf("%lld",res):printf("%lld",res1);
}

//1 2 3 4 5 6 7 8 9 10

#include<stdio.h>
#include<string.h>
#include<limits.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
long long int gcd(long long int a,long long int b){
	if(a==1)
		return b;
	return(a,b%a);
}
long long int max(long long int a,long long int b){
	return a>b?a:b;
}
int main(){
	long long int a,b,c,d,e;
	int cnt=0;

	scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e);
	long long int res = 0;
	long long int res1 =0;
	res= ((a/b)*d) + ( max((a/b) - ((a/b+a/c)-(a/(b*c))),0 ) * e);
	res1= ((a/c)*e) + ( max((a/c) - ((a/b+a/c)-(a/(b*c))),0 ) * d);
	res>res1?printf("%lld",res):printf("%lld",res1);
}

#include<stdio.h>
#include<string.h>
#include<limits.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
long long int gcd(long long int a,long long int b){
long long int x =a;
while(a){
	x=a; a=b%a; b=x;
}
return b;
}
long long int lcm(long long int a,long long int b){
	return (a*b)/gcd(a,b);
}
int main(){
long long int a,b,c,d,e;
	int cnt=0;

	scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e);
	if(b==c){
		if(d>e){
			printf("%lld",(a/b)*d);
		}
		else printf("%lld",(a/c)*e);
		return 0;
	}

	long long int res = 0;
	long long int res1 =0;
	res= ((a/b)*d) + ( abs((a/c) - a/lcm(b,c)) * e);
	res1= ((a/c)*e) + ( abs((a/b) - a/lcm(b,c)) * d);
	printf("%lld  ",res);printf("%lld",res1);
}

//1 2 3 4 5 6 7 8 9 10

#include<stdio.h>
#include<string.h>
#include<limits.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
int arr[250];

int main(){
	int a,b,c,d,e;
	int cnt=0;

	scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
	long long int res = 0;
	long long int res1 =0;
	res= ((a/b)*d) + ( abs((a/b) - ((a/b+a/c)-(a/(b*c))) ) * e);
	res1= ((a/c)*e) + ( abs((a/c) - ((a/b+a/c)-(a/(b*c))) ) * d);
	if(res>res1){
		printf("%lld",res);
	}
	else printf("%lld",res1);
}

#include <stdio.h>

int main()
{
    long long int n,a,b,p,q,na = 0,nb = 0,nab = 0,ans = 0;
    scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);

    na = n/a;
    nb = n/b;
    nab = n/(a*b);
    na -= nab;
    nb -= nab;

    if(p > q)
    {
        ans = (na+nab)*p + nb*q;
    }
    else
    {
        ans = na*p + (nb+nab)*q;
    }
    printf("%lld",ans);
    return 0;
}

#include <stdio.h>

int main()
{
    long long int n,a,b,p,q,na = 0,nb = 0,nab = 0,ans = 0;
    scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);

    na = n/a;
    nb = n/b;
    nab = n/(a*b);
    na -= nab;
    nb -= nab;

    if(p > q)
    {
        ans = (na+nab)*p + nb*q;
    }
    else
    {
        ans = na*p + (nb+nab)*q;
    }
    printf("%I64d",ans);
    return 0;
}

#include <stdio.h>

int main()
{
    int n,a,b,p,q,na = 0,nb = 0,nab = 0,ans = 0;
    scanf("%d %d %d %d %d",&n,&a,&b,&p,&q);

    na = n/a;
    nb = n/b;
    nab = n/(a*b);
    na -= nab;
    nb -= nab;

    if(p > q)
    {
        ans = (na+nab)*p + nb*q;
    }
    else
    {
        ans = na*p + (nb+nab)*q;
    }
    printf("%d",ans);
    return 0;
}

#ifdef ONLINE_JUDGE
    #define NDEBUG 1
#endif
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <math.h>

#define long int64_t
#define fore(i,k,n) for (int _k = (k), _n = (n), i = _k; i <= _n; ++i)
#define forr(i,n,k) for (int _k = (k), _n = (n), i = _n; i >= _k; --i)
#define LIST_INIT_CAP 4
#define HASH_INIT_CAP 64
#define HASH_SKIP 11
#define TREE_INIT_CAP 1024
#define TREE_MAX_HEIGHT 64
#define DEQUE_INIT_CAP 1024
#define HEAP_INIT_CAP 1024
#define TAKEN 1
#define EMPTY 0
#define TOMB -1
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))

#define N 3005

int main() {

    int n, a, b, p, q, pq;
    scanf("%d %d %d %d %d", &n, &a, &b, &p, &q);
    pq = max(p, q);
    long ad = n / a;
    long bd = n / b;
    long abd = n / (a * b);
    long answer = ((ad - abd) * p) + ((bd - abd) * q) + (abd * pq);
    printf("%I64d", answer);

    return 0;
}

#ifdef ONLINE_JUDGE
    #define NDEBUG 1
#endif
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <math.h>

#define long int64_t
#define fore(i,k,n) for (int _k = (k), _n = (n), i = _k; i <= _n; ++i)
#define forr(i,n,k) for (int _k = (k), _n = (n), i = _n; i >= _k; --i)
#define LIST_INIT_CAP 4
#define HASH_INIT_CAP 64
#define HASH_SKIP 11
#define TREE_INIT_CAP 1024
#define TREE_MAX_HEIGHT 64
#define DEQUE_INIT_CAP 1024
#define HEAP_INIT_CAP 1024
#define TAKEN 1
#define EMPTY 0
#define TOMB -1
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))

#define N 3005

int gcd(int a, int b) {
    if (a == 0)
        return b;
    else
        return gcd(b % a, a);
}

int lcm(int a, int b) {
    return (a / gcd(a, b)) * b;
}
int main() {

    int n, a, b, p, q, pq;
    scanf("%d %d %d %d %d", &n, &a, &b, &p, &q);
    pq = max(p, q);
    long ad = n / a;
    long bd = n / b;
    long abd = n / lcm(a, b);
    long answer = ((ad - abd) * p) + ((bd - abd) * q) + (abd * pq);
    printf("%I64d", answer);

    return 0;
}

#include<stdio.h>
int main(void)
{
  long long int n,i,a,b,p,q,k,m,l,ans;

    scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q);

     k=n/a;
     m=n/b;
     l=n/(a*b);
     if(p>q) m-=l;
     else k-=l;
     ans=(k*p)+(m*q);
     printf("%I64d",ans);

}

#include<stdio.h>
int main()
{
	long long i, n, a, b, p, q, sum1 = 0, sum2 = 0, sum12 = 0;
	scanf("%I64d %I64d %I64d %I64d %I64d", &n, &a, &b, &p, &q);
	sum12 = n / a / b;
	sum1 = n / a - sum12;
	sum2 = n / b - sum12;
	if (p >= q)
		printf("%I64d", sum1 * p + sum2 * q + sum12 * p);
	else
		printf("%I64d", sum1 * p + sum2 * q + sum12 * q);
	return 0;
}

#include <stdio.h>
long fun(long long  m,long long  n)
{
    long a=m,b=n,k;
    while(1)
    {
        k=a%b;
        if(k)
        {
            a=b;
            b=k;
        }
        else break;
    }
    return m*n/b;
}
int main()
{
    long long n,a,b,p,q,i,j,k;
    scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q);
    i=n/a;
    j=n/b;
    k=fun(a,b);
    if(p<q)
    {
        i-=n/k;
    }
    else j-=n/k;
    printf("%I64d\n",i*p+j*q);
}

#include <stdio.h>
int fun(int m,int n)
{
    int a=m,b=n,k;
    while(1)
    {
        k=a%b;
        if(k)
        {
            a=b;
            b=k;
        }
        else break;
    }
    return m*n/b;
}
int main()
{
    long long n,a,b,p,q,i,j,k;
    scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q);
    i=n/a;
    j=n/b;
    k=fun(a,b);
    if(p<q)
    {
        i-=n/k;
    }
    else j-=n/k;
    printf("%I64d\n",i*p+j*q);
}

#include<stdio.h>
int main()
{
    long long int n,a,b,p,q,t,x,y,z,m;
    scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q);
    x=n/a;
    y=n/b;
    m=a*b;
    z=n/m;
    if(p>q)
    {
        t=x*p+(y-z)*q;
        printf("%I64d\n",t);
    }
    else
    {
        t=(x-z)*p+y*q;
        printf("%I64d\n",t);
    }
    return 0;

}

#include<stdio.h>
int main()
{
    int n,a,b,p,q,x,y,z;
    long long int t,m;
    scanf("%d%d%d%d%d",&n,&a,&b,&p,&q);
    x=n/a;
    y=n/b;
    m=a*b;
    z=n/m;
    if(p>q)
    {
        t=x*p+(y-z)*q;
        printf("%I64d\n",t);
    }
    else
    {
        t=(x-z)*p+y*q;
        printf("%I64d\n",t);
    }
    return 0;

}

#include <stdio.h>

#define MAX(x,y) (x<y)?y:x;
#define MIN(x,y) (x<y)?x:y;

int gcd(int a, int b){ return b==0?a:gcd(b, a%b);}

int lcm(int a, int b){ return a*(b/gcd(a,b));}

/*
long long lcm(long long a, long long b){
	int M=MAX(a,b);
	if(!(M%a)&&!(M%b)) return M;
	for(int i=(a*b)-1; i>M*2; i--){
		//printf("i %d\n" , i);
		if(!(i%a) && !(i%b)) return i;
	}
	return a*b;
	/*for(int i=M; i<=(a*b); i++){
		if(!(i%a)&&!(i%b)) return i;
	}
}*/

int main(){
	long long N, a, b, p, q;

	scanf("%llu %llu %llu %llu %llu", &N, &a, &b, &p, &q);

	int com=lcm(a,b);
	//printf("%d  ", com);
	if(com==-1) com=0;
	if(com) com=N/com;
	int red= N/a;
	int blue = N/b;

	if(p>q) blue-=com;
	else red-=com;

	printf("%llu\n", (red*p)+(blue*q));
	return 0;

}

#include <stdio.h>

#define MAX(x,y) (x<y)?y:x;
#define MIN(x,y) (x<y)?x:y;

int gcd(int a, int b){
	int M=MAX(a,b);
	int N=MIN(a,b);
	if(!(M%N)) return N;
	if(a==1 || b==1) return 1;
	for(int i=M/N; i>2; i--){
		if(!(a%i) && !(b%i)) return i;
	}
	return -1;
}

int lcm(int a, int b){
	int M=MAX(a,b);
	if(!(M%a)&&!(M%b)) return M;

	return -1;
	/*for(int i=M; i<=(a*b); i++){
		if(!(i%a)&&!(i%b)) return i;
	}*/
}

int main(){
	int a, b;

	int T;
	scanf("%d", &T);
	for(int i=0; i<T; i++){
		scanf("%d %d", &a, &b);
		int gc=gcd(a,b);
		int lc=lcm(a,b);
		if(gc==-1 || a>b || lc==-1){
			printf("-1\n");
			continue;
		}

		printf("%d %d\n", gc, lc);
	}
	return 0;
}

#include <stdio.h>

#define MAX(x,y) (x<y)?y:x;
#define MIN(x,y) (x<y)?x:y;

int lcm(int a, int b){
	int M=MAX(a,b);
	if(!(M%a)&&!(M%b)) return M;

	return a*b;
	/*for(int i=M; i<=(a*b); i++){
		if(!(i%a)&&!(i%b)) return i;
	}*/
}

int main(){
	int N, a, b, p, q;

	scanf("%d %d %d %d %d", &N, &a, &b, &p, &q);

	int com=lcm(a,b);

	if(com==-1) com=0;
	if(com) com=N/com;
	int red= N/a;
	int blue = N/b;

	if(p>q) blue-=com;
	else red-=com;

	printf("%d\n", (red*p)+(blue*q));
	return 0;

}

#include <stdio.h>

#define MAX(x,y) (x<y)?y:x;
#define MIN(x,y) (x<y)?x:y;

long long lcm(long long a, long long b){
	int M=MAX(a,b);
	if(!(M%a)&&!(M%b)) return M;

	return a*b;
	/*for(int i=M; i<=(a*b); i++){
		if(!(i%a)&&!(i%b)) return i;
	}*/
}

int main(){
	long long N, a, b, p, q;

	scanf("%llu %llu %llu %llu %llu", &N, &a, &b, &p, &q);

	int com=lcm(a,b);

	if(com==-1) com=0;
	if(com) com=N/com;
	int red= N/a;
	int blue = N/b;

	if(p>q) blue-=com;
	else red-=com;

	printf("%llu\n", (red*p)+(blue*q));
	return 0;

}

#include <stdio.h>
#include <stdlib.h>
typedef unsigned long long int ulli;

ulli min(ulli a, ulli b)
{
	return (a<b)?a:b;
}

ulli max(ulli a, ulli b)
{
	return (a>b)?a:b;
}

ulli choc(ulli n, ulli a, ulli b, ulli p, ulli q)
{
	if(n<a)
		return 0;
	ulli tiles=n,total=0;
	total=((n/a)*p + (n/b)*q);
	if(n<2*(a*b))
		{
			while (tiles>0)
			{
				if(tiles%a == 0 && tiles %b ==0)
					total-=min(p,q);
				tiles--;
			}
		}
	else if(a%b==0 || b%a==0)
		total-=((n/max(a,b)*min(p,q)));
	else
		total-=((n/(a*b))*min(p,q));
	return total;
}

int
main (int argc, char *argv[])
{
	ulli i,n,a,b,p,q;
	scanf("%lld %lld %lld %lld %lld",&n,&a, &b, &p, &q);
	//printf("%lld",((n/a)*p + (n/b)*q)-(n/(a*b)*min(p,q)));
	printf("%lld",choc(n,a,b,p,q) );
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
typedef unsigned long long int ulli;

ulli gcd(ulli x, ulli y)
{
	if(y==0) return x;
	else return gcd(y,x%y);
}

ulli min(ulli a, ulli b)
{
	return (a<b)?a:b;
}

ulli max(ulli a, ulli b)
{
	return (a>b)?a:b;
}

ulli choc(ulli n, ulli a, ulli b, ulli p, ulli q)
{
	if(n<a)
		return 0;
	ulli tiles=n,total=0;
	total=((n/a)*p + (n/b)*q)-((n/(a*b/gcd(a,b))*min(p,q)));
	return total;
}

int
main (int argc, char *argv[])
{
	ulli i,n,a,b,p,q;
	scanf("%lld %lld %lld %lld %lld",&n,&a, &b, &p, &q);

	printf("%lld",choc(n,a,b,p,q) );
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
typedef unsigned long long int ulli;

ulli min(ulli a, ulli b)
{
	return (a<b)?a:b;
}

int
main (int argc, char *argv[])
{
	ulli i,n,a,b,p,q;
	scanf("%lld %lld %lld %lld %lld",&n,&a, &b, &p, &q);
	printf("%lld",((n/a)*p + (n/b)*q)-(n/(a*b)*min(p,q)));
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
typedef unsigned long long int ulli;

ulli min(ulli a, ulli b)
{
	return (a<b)?a:b;
}

ulli max(ulli a, ulli b)
{
	return (a>b)?a:b;
}

ulli choc(ulli n, ulli a, ulli b, ulli p, ulli q)
{
	if(n<a)
		return 0;
	ulli tiles=n,total=0;
	total=((n/a)*p + (n/b)*q);
	if(n<a*b)
		{
			while (tiles>0)
			{
				if(tiles%a == 0 && tiles %b ==0)
					total-=min(p,q);
				tiles--;
			}
		}
	else if(a%b==0 || b%a==0)
		total-=((n/max(a,b)*min(p,q)));
	else
		total-=((n/(a*b))*min(p,q));
	return total;
}

int
main (int argc, char *argv[])
{
	ulli i,n,a,b,p,q;
	scanf("%lld %lld %lld %lld %lld",&n,&a, &b, &p, &q);
	//printf("%lld",((n/a)*p + (n/b)*q)-(n/(a*b)*min(p,q)));
	printf("%lld",choc(n,a,b,p,q) );
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
typedef unsigned long long int ulli;

ulli gcd(ulli x, ulli y)
{
	if(y==0) return x;
	else return gcd(y,x%y);
}

ulli min(ulli a, ulli b)
{
	return (a<b)?a:b;
}

ulli max(ulli a, ulli b)
{
	return (a>b)?a:b;
}

ulli choc(ulli n, ulli a, ulli b, ulli p, ulli q)
{
	if(n<a)
		return 0;
	ulli tiles=n,total=0;
	total+=((n/a)*p + (n/b)*q)-((n/(a*b/gcd(a,b))*min(p,q)));
	return total;
}

int
main (int argc, char *argv[])
{
	ulli i,n,a,b,p,q;
	scanf("%lld %lld %lld %lld %lld",&n,&a, &b, &p, &q);

	printf("%lld",choc(n,a,b,p,q) );
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
typedef unsigned long long int ulli;

ulli numbers(ulli n, ulli k)
{
	ulli x=n+k;
	while(x)
	{
		if(x%k==0)
			break;
		x--;
	}
	return x;
}

int
main (int argc, char *argv[])
{
	ulli n,k;
	scanf("%lld %lld",&n,&k);
	printf("%lld",numbers(n,k));
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
typedef unsigned long long int ulli;

ulli min(ulli a, ulli b)
{
	return (a<b)?a:b;
}

ulli max(ulli a, ulli b)
{
	return (a>b)?a:b;
}

ulli choc(ulli n, ulli a, ulli b, ulli p, ulli q)
{
	if(n<a)
		return 0;
	ulli tiles=n,total=0;
	total=((n/a)*p + (n/b)*q);
	if(a%b==0 || b%a==0)
		total-=((n/max(a,b)*min(p,q)));
	else
		total-=((n/(a*b))*min(p,q));
	return total;
}

int
main (int argc, char *argv[])
{
	ulli i,n,a,b,p,q;
	scanf("%lld %lld %lld %lld %lld",&n,&a, &b, &p, &q);
	//printf("%lld",((n/a)*p + (n/b)*q)-(n/(a*b)*min(p,q)));
	printf("%lld",choc(n,a,b,p,q) );
	return 0;
}

#include<stdio.h>

long long int gcd(int a,int b)
{
  long long int c;
  while ( a != 0 ) {
     c = a; a = b%a;  b = c;
  }
  return b;
}

long long int lcd(int a,int b)
{
  return (a*b)/gcd(a,b);
}

int main()
{
 long long int n,a,b,p,q,red,blue,common,ans;

 scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);

 red = (n/a)-(n/lcd(a,b));
 blue = (n/b)-(n/lcd(a,b));
 common = n/lcd(a,b);

 if(p>=q) ans = red*p+blue*q+common*p;
 else ans = red*p+blue*q+common*q;

 printf("%lld\n",ans);

return 0;
}

#include<stdio.h>
int main()
{
     long long int n,a,b,p,q,A,B,C,RC,BC,D,t1,t2;

    scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);

    if(a%b==0 || b%a==0)
    {
        A=n/a;
        B=n/b;

        if(a>b)
        {
            if(p>q)
           { t1 = A*p;
              B = B -A;
             t2 = B*q;
           }
           else
           {
               t1 = A*q;
               B = B -A;
               t2 = B*q;
           }
           printf("%lld",t1+t2);
        }
        else
        {
            if(p>q)
           { t1 = B*p;
             A = A -B;
             t2 = A*q;
           }
           else
           {
               t1 = B*q;
               A = A -B;
               t2 = A*q;
           }
           printf("%lld",t1+t2);

        }
    }
    else
    {

        A = n/a;

        B= n/b;

        C = n/(a*b);

       A = A -C;
       B = B -C;

       RC = A*p;
       BC = B*q;

       if(p>q)
       {
           D = C*p;

       }

        else
         {
             D = C*q;
          }
          printf("%lld",RC+BC+D);
    }
}

#include<stdio.h>
int main()
{
     long long int n,a,b,p,q,A,B,C,RC,BC,D,t1,t2;

    scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);

    if((a%b==0 || b%a==0)&& (a!=1 && b!=1))
    {
        A=n/a;
        B=n/b;

        if(a>b)
        {
            if(p>q)
           { t1 = A*p;
              B = B -A;
             t2 = B*q;
           }
           else
           {
               t1 = A*q;
               B = B -A;
               t2 = B*q;
           }
           printf("%lld",t1+t2);
        }
        else
        {
            if(p>q)
           { t1 = B*p;
             A = A -B;
             t2 = A*q;
           }
           else
           {
               t1 = B*q;
               A = A -B;
               t2 = A*q;
           }
           printf("%lld",t1+t2);

        }
    }
    else
    {

        A = n/a;

        B= n/b;

        C = n/(a*b);

       A = A -C;
       B = B -C;

       RC = A*p;
       BC = B*q;

       if(p>q)
       {
           D = C*p;

       }

        else
         {
             D = C*q;
          }
          printf("%lld",RC+BC+D);
    }
}

#include<stdio.h>
int main()
{
     long long int n,a,b,p,q,A,B,C,RC,BC,D,i;

    scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&p,&q);
    A=0; B=0; C=0;

        A = n/a;

        B= n/b;

        C = n/(a*b);

    A = A -C;
    B = B -C;

    RC = A*p;
    BC = B*q;

    if(p>q)
    {
        D = C*p;

    }

    else
    {
        D = C*q;
    }
    printf("%lld",RC+BC+D);
}

#include<stdio.h>
long hcf(long int a,long int b)
{
    while(a!=b)
    {
        if(a>b)
        a=a-b;
        else
        b=b-a;
    }
    return a;
}
int main()
{
    long int n,a,b,p,q,i,x;
    long long int sum=0;
    scanf("%ld %ld %ld %ld %ld",&n,&a,&b,&p,&q);
    x=a*b/hcf(a,b);
    sum+=(long long)p*(n/a-(n/x));
    sum+=q*(n/b-(n/x));
    if(p>q)
    sum+=(long long)p*(n/x);
    else
    sum+=(long long)q*(n/x);
    printf("%I64d",sum);
}

#include<stdio.h>
int main()
{
    long int n,a,b,p,q,i;
    long long int sum=0;
    scanf("%ld %ld %ld %ld %ld",&n,&a,&b,&p,&q);
    sum+=(long long)p*(n/a-(n/(a*b)));
    sum+=q*(n/b-(n/(a*b)));
    if(p>q)
    sum+=(long long)p*(n/(a*b));
    else
    sum+=(long long)q*(n/(a*b));
    printf("%I64d",sum);
}

#include<stdio.h>
int main()
{
    long int n,a,b,p,q,i;
    long long int sum=0;
    scanf("%ld %ld %ld %ld %ld",&n,&a,&b,&p,&q);
    sum+=p*(n/a-(n/(a*b)));
    sum+=q*(n/b-(n/(a*b)));
    if(p>q)
    sum+=p*n/(a*b);
    else
    sum+=q*n/(a*b);
    printf("%I64d",sum);
}

#include<stdio.h>
int main()
{
    long int n,a,b,p,q,i;
    long long int sum=0;
    scanf("%ld %ld %ld %ld %ld",&n,&a,&b,&p,&q);
    sum+=p*(n/a-(n/(a*b)));
    sum+=q*(n/b-(n/(a*b)));
    if(p>q)
    sum+=p*(n/(a*b));
    else
    sum+=q*(n/(a*b));
    printf("%I64d",sum);
}

#include<stdio.h>
long hcf(long int a,long int b)
{
    while(a!=b)
    {
        if(a>b)
        a=a-b;
        else
        b=b-a;
    }
    return a;
}
int main()
{
    long int n,a,b,p,q,i,x;
    long long int sum=0;
    scanf("%ld %ld %ld %ld %ld",&n,&a,&b,&p,&q);
    x=n/hcf(a,b);
    sum+=(long long)p*(n/a-(n/x));
    sum+=q*(n/b-(n/x));
    if(p>q)
    sum+=(long long)p*(n/x);
    else
    sum+=(long long)q*(n/x);
    printf("%I64d",sum);
}

#include<stdio.h>
long hcf(long int a,long int b)
{
    while(a!=b)
    {
        if(a>b)
        a=a-b;
        else
        b=b-a;
    }
    return a;
}
int main()
{
    long int n,a,b,p,q,i,x;
    long long int sum=0;
    scanf("%ld %ld %ld %ld %ld",&n,&a,&b,&p,&q);
    x=((long long)a*b)/hcf(a,b);
    sum+=(long long)p*(n/a-(n/x));
    sum+=q*(n/b-(n/x));
    if(p>q)
    sum+=(long long)p*(n/x);
    else
    sum+=(long long)q*(n/x);
    printf("%I64d",sum);
}

#include<stdio.h>
int main()
{
    long long int n,a,b,p,q,sum,i,sum1,j;
    while(scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q)!=EOF)
    {
        if(b>a)
        {
            sum=0;
            for(i=1; i<=n; i++)
            {
                if(i%b==0)
                {
                    sum=sum+q;
                }
            }
            sum1=0;
            for(j=1; j<=n; j++)
            {
                if(j%b==0) continue;
                if(j%a==0)
                {
                    sum1=sum1+p;
                }
            }

        }
        else if(a>b)

        {
            sum=0;
            for(i=1; i<=n; i++)
            {
                if(i%a==0)
                {
                    sum=sum+p;
                }
            }
            sum1=0;
            for(j=1; j<=n; j++)
            {
                if(j%a==0) continue;
                if(j%b==0)
                {
                    sum1=sum1+q;
                }
            }

        }
        printf("%lld\n",sum+sum1);

    }
    return 0;
}

#include <stdio.h>

int gcd(int x, int y){
    if(y==0) return x;
    else return gcd(y, x%y);
}
int main()
{
    int n, a, b, p, q, lc, c;
    int na, nb, nab;

    while(scanf("%d %d %d %d %d", &n, &a, &b, &p, &q) != EOF){
        na = n/a;
        nb = n/b;
        lc = a*b/gcd(a,b);
        nab = n/lc;
        if(p>q) nb -= nab;
        else na -= nab;
        c = na*p + nb*q;
        printf("%d\n", c);
    }
    return 0;
}

#include<stdio.h>
int main()
{
    int n,a,b,p,q,count1=0,count2=0,i,temp;
    long long int s=0;
    scanf("%d%d%d%d%d",&n,&a,&b,&p,&q);
int d,e;
    if(a>b)
    {
         d=b;
         e=a;
        do
        {
            temp= a%b;
            a=b;
            b=temp;
        }
        while(temp!=0);
        temp=a;
        b=d;
        a=e;
    }
    else
    {
         d=a;
         e=b;
        do
        {
            temp= b%a;
            b=a;
            a=temp;
        }
        while(temp!=0);
        temp=b;
        a=d;
        b=e;
    }
d=(a*b)/temp;
    count1=(n/a);
    count2=(n/b);
    if(p>q){
        count2=count2-(n/d);
    }
else {
            count1=count1-(n/d);

}
    s=(count1*p)+(count2*q);
    printf("%I64d",s);

}

#include<stdio.h>
#include<math.h>
int main()
{
    int n,a,b,p,q,count1=0,count2=0,i,temp;
    long long int s=0;
    scanf("%d%d%d%d%d",&n,&a,&b,&p,&q);
    int d,e;
    if(a>b)
    {
        d=b;
        e=a;
        do
        {
            temp= a%b;
            a=b;
            b=temp;
        }
        while(temp!=0);
        temp=a;
        b=d;
        a=e;
    }
    else
    {
        d=a;
        e=b;
        do
        {
            temp= b%a;
            b=a;
            a=temp;
        }
        while(temp!=0);
        temp=b;
        a=d;
        b=e;
    }
    d=(a*b)/temp;
    count1=ceil(n/a);
    count2=ceil(n/b);
    if(p>q)
    {
        count2=count2-ceil(n/d);
    }
    else
    {
        count1=count1-(n/d);

    }
    s=(count1*p)+(count2*q);
    printf("%I64d",s);

}

#include<stdio.h>
int main(){
     int n,a,b,p,q,count1=0,count2=0,i;
     long long int s=0;
    scanf("%d%d%d%d%d",&n,&a,&b,&p,&q);
    if(p>q){
        for(i=2;i<=n;i++){
            if(i%a==0&&i%b!=0)
                count1++;
            else if(i%a!=0&&i%b==0)
                count2++;
            else if(i%a==0&&i%b==0)
                count1++;
        }
    }
    else{
         for(i=2;i<=n;i++){
            if(i%a==0&&i%b!=0)
                count1++;
            else if(i%a!=0&&i%b==0)
                count2++;
            else if(i%a==0&&i%b==0)
                count2++;
        }
    }
    s=(count1*p)+(count2*q);
    printf("%I64d",s);

}

#include<stdio.h>
#include<math.h>
int main()
{
    int n,a,b,p,q,count1=0,count2=0,i,temp;
    long long int s=0;
    scanf("%d%d%d%d%d",&n,&a,&b,&p,&q);
    int d,e;
    if(a>b)
    {
        d=b;
        e=a;
        do
        {
            temp= a%b;
            a=b;
            b=temp;
        }
        while(temp!=0);
        temp=a;
        b=d;
        a=e;
    }
    else
    {
        d=a;
        e=b;
        do
        {
            temp= b%a;
            b=a;
            a=temp;
        }
        while(temp!=0);
        temp=b;
        a=d;
        b=e;
    }
    d=(a*b)/temp;
    count1=floor(n/a);
    count2=floor(n/b);
    if(p>q)
    {
        count2=count2-floor(n/d);
    }
    else
    {
        count1=count1-floor(n/d);

    }
    s=(count1*p)+(count2*q);
    printf("%I64d",s);

}

#include <stdio.h>

void swap(long long* a, long long* b) {
    long long tmp = *a;
    *a = *b;
    *b = tmp;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

long long lcm(long long a, long long b) {
    return (a / gcd(a, b)) * b;
}

int main() {
    long long n, a, b, p, q;
    long long res = 0;

    scanf("%d%d%d%d%d", &n, &a, &b, &p, &q);
    if (p > q) {
        swap(&p, &q);
        swap(&a, &b);
    }

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

    printf("%I64d\n", res);
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int gcd(int a, int b)
{
	return b == 0 ? a : gcd(b, a % b);
}

int lcm(int a, int b)
{
	return a * (b / gcd(a, b));
}

int main()
{
	long long n, a, b, p, q, x, y, best;
	long long result=0;

	scanf("%lld %lld %lld %lld %lld", &n, &a, &b, &p, &q);

	x = n / a;
	y = n / b;

	best = n / lcm(a, b);
	/*if (a > b && a%b == 0)
	{
		best = n/a;
	}
	else if (b > a && b%a == 0)
	{
		best = n/b;
	}*/

	if (p > q)
	{
		result = (x*p) + ((y - best)*q);
	}
	else
	{
		result = (y*q) + ((x - best)*p);
	}

	printf("%lld\n", result);

	return 0;
}

/* 1520882613945 */

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	int i;
	long long n, a, b, p, q, x, y, best;
	long long result=0;

	scanf("%lld", &n);
	scanf("%lld", &a);
	scanf("%lld", &b);
	scanf("%lld", &p);
	scanf("%lld", &q);

	x = n / a;
	y = n / b;

	best = n / (a*b);
	if (a > b && a%b == 0)
	{
		best = a;
	}
	else if (b > a && b%a == 0)
	{
		best = b;
	}

	if (p > q)
	{
		result = (x*p) + ((y - best)*q);
	}
	else
	{
		result = (y*q) + ((x - best)*p);
	}

	printf("%lld\n", result);

	return 0;
}

/* 1520870754018 */

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	int i;
	long long n, a, b, p, q, x, y, best;
	long long result=0;

	scanf("%lld", &n);
	scanf("%lld", &a);
	scanf("%lld", &b);
	scanf("%lld", &p);
	scanf("%lld", &q);

	x = n / a;
	y = n / b;

	best = n / (a*b);
	if (a > b && a%b == 0)
	{
		best = n/a;
	}
	else if (b > a && b%a == 0)
	{
		best = n/b;
	}

	if (p > q)
	{
		result = (x*p) + ((y - best)*q);
	}
	else
	{
		result = (y*q) + ((x - best)*p);
	}

	printf("%lld\n", result);

	return 0;
}

/* 1520870931810 */

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
	int i;
	long long n, a, b, p, q, x, y, best;
	long long result=0;

	scanf("%lld", &n);
	scanf("%lld", &a);
	scanf("%lld", &b);
	scanf("%lld", &p);
	scanf("%lld", &q);

	x = n / a;
	y = n / b;
	best = n / (a*b);

	if (p > q)
	{
		result = (x*p) + ((y - best)*q);
	}
	else
	{
		result = (y*q) + ((x - best)*p);
	}

	printf("%lld\n", result);

	return 0;
}

/* 1520869611037 */

#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#include<strings.h>
#include<math.h>
#define true 1
#define false 0
#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a
//SUPERMEAT BOY
//JOTY AND CHOCOLATE

int main()
{
    int n,a,b,p,q,mtp;
    scanf("%d%d%d%d%d",&n,&a,&b,&p,&q);
    mtp=min(p,q);
    printf("%d",p*(n/a)+q*(n/b)-(mtp*(n/(a*b))));
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
#include<strings.h>
#include<math.h>
#define true 1
#define false 0
#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a
//SUPERMEAT BOY
//JOTY AND CHOCOLATE
int gcd(int a, int b)
{
    // base case
    if (a == b)
        return a;

    // a is greater
    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}

// Function to return LCM of two numbers
int lcm(int a, int b)
{
    return (a*b)/gcd(a, b);
}
int main()
{
    int n,a,b,p,q,mtp;
    int lcm(int,int);
    int gcd(int ,int);

    scanf("%d%d%d%d%d",&n,&a,&b,&p,&q);
    mtp=min(p,q);
    printf("%d",p*(n/a)+q*(n/b)-(mtp*(n/(lcm(a,b)))));
    return 0;
}

#include<stdio.h>
int main()
{
long long int n,a,b,p,q,i,sum=0;
scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q);
long long int c;
if(a>b)
c=b;
else
c=a;
if(a==1 && b!=1)
sum=sum+n*p;
if(b==1 && a!=1)
sum=sum+n*q;
for(i=c;i<=n;i++)
{
if(i%a==0 && i%b!=0 && a!=1)
sum=sum+p;
if(i%b==0 && i%a!=0 && b!=1)
sum=sum+q;
if(i%a==0 && i%b==0 && a!=1 && b!=1)
{
if(a>b)
sum=sum+p;
else
sum=sum+q;
}
}
printf("%lld\n",sum);
return 0;
}

#include<stdio.h>
int main()
{
long long int n,a,b,p,q,i,sum=0;
scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q);
if(n==1)
{
if(a==1 && b!=1)
sum=sum+p;
if(b==1 && a!=1)
sum=sum+q;
if(a==1 && b==1)
{
if(p>q)
sum=sum+p;
else
sum=sum+q;
}
}
long long int c;
if(a>b)
c=b;
else
c=a;
if(a==1 && b!=1)
sum=sum+n*p;
if(b==1 && a!=1)
sum=sum+n*q;
for(i=c;i<=n;i++)
{
if(i%a==0 && i%b!=0 && a!=1)
sum=sum+p;
if(i%b==0 && i%a!=0 && b!=1)
sum=sum+q;
if(i%a==0 && i%b==0 && a!=1 && b!=1)
{
if(p>q)
sum=sum+p;
else
sum=sum+q;
}
}
printf("%lld\n",sum);
return 0;
}

#include <stdio.h>
#ifndef _TJYTLXWXHYZQFW_COMMON_H
#define _TJYTLXWXHYZQFW_COMMON_H
#include <limits.h>
#define offset(t,m) ((unsigned long)&(((t*)0)->m))
#define container_of(a,t,m) ((t*)((unsigned long)a-offset(t,m)))
#define ULL1 ((unsigned long long )1)
#define LL(x) ((long long)(x))
#define SWP(a, b) if ((a) != (b)) do {(a) ^= (b); (b) ^= (a); (a) ^= (b);} while(0)
#define IOF(p) ((p) = ((p) < 0 ? INT_MAX : (p)))
#define LLOF(p) ((p) = ((p) < 0 ? LLONG_MAX :(p)))
#define ir(x, start, end) ((x) >= (start) && (x) < (end))
#define ire(x, start, end) ((x) >= (start) && (x) <= (end))
#define max(x,y) ((x) < (y) ? (y) : (x))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define abv(x) ((x) < 0 ? (x) * (-1) : (x))
#define forn(i, n) for ((i) = 0; (i) < (n); (i) += 1)
#define fore(i, n) for ((i) = 0; (i) <= (n); (i) += 1)
#define forr(i, s, e) for((i) = (s); (i) < (e); (i) += 1)
#define forre(i, s, e) for((i) = (s); (i) <= (e); (i) += 1)
#endif
int main(void)
{
	long long n, a, b, p, q;
	scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &p, &q);
	printf("%lld\n", (n / a) * p + (n / b) * q - n / (a * b) * min(p, q));
	return 0;
}

#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int n, a, b, p, q, red, blue, mixed;
    scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q);
    mixed = n/(a*b);
    red = n/a;
    blue = n/b;
    if(p > q){
        printf("%I64d",((red*p)+(blue-mixed)*q));
    }
    else {
        printf("%I64d",((blue*q)+(red-mixed)*p));
    }
    return 0;

}

#include<stdio.h>
int main(){
	int i,n,a,b,p,q,max;
	long long int ans;
	while(~scanf("%d%d%d%d%d",&n,&a,&b,&p,&q)){
		ans=0;
		if(q>=p){
			ans+=n/b*q;
			for(i=a;i<=n;i+=a)
				if(i%b!=0)
					ans+=p;
		}
		else{
			ans+=n/a*p;
			for(i=b;i<=n;i+=b)
				if(i%a!=0)
					ans+=q;
		}
		printf("%d\n",ans);
	}
	return 0;
}

#include<stdio.h>
int gongbeishu(int a,int b){
	int t,aa=a,bb=b;
	if(a<b){
		t=a;a=b;b=t;
	}
	while(a%b!=0){
		t=a%b;
		a=b;
		b=t;
	}
	return aa*bb/b;
}
int main(){
	long long int i,n,a,b,p,q;
	long long int ans;
	while(~scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q)){
		ans=0;
		if(q>=p){
			ans+=n/b*q;
			if(a!=b){
				ans+=n/a*p;
				i=gongbeishu(a,b);
				ans-=n/i*p;
			}
		}
		else{
			ans+=n/a*p;
			if(a!=b){
				ans+=n/b*q;
				i=gongbeishu(a,b);
				ans-=n/i*q;
			}
		}
		printf("%I64d\n",ans);
	}
	return 0;
}

#include<stdio.h>
int main(){
	int i,n,a,b,p,q,max;
	long long int ans;
	while(~scanf("%d%d%d%d%d",&n,&a,&b,&p,&q)){
		ans=0;
		if(q>=p){
			ans+=n/b*q;
			for(i=a;i<=n;i+=a)
				if(i%b!=0)
					ans+=p;
		}
		else{
			ans+=n/a*p;
			for(i=b;i<=n;i+=b)
				if(i%a!=0)
					ans+=q;
		}
		printf("%ld\n",ans);
	}
	return 0;
}

#include<stdio.h>
int main(){
	int i,n,a,b,p,q,max;
	long long int ans;
	while(~scanf("%d%d%d%d%d",&n,&a,&b,&p,&q)){
		ans=0;
		if(q>=p){
			ans+=n/b*q;
			for(i=a;i<=n;i+=a)
				if(i%b!=0)
					ans+=p;
		}
		else{
			ans+=n/a*p;
			for(i=b;i<=n;i+=b)
				if(i%a!=0)
					ans+=q;
		}
		printf("%l64d\n",ans);
	}
	return 0;
}

#include<stdio.h>
int main(){
	int i,n,a,b,p,q,max;
	long long int ans;
	while(~scanf("%d%d%d%d%d",&n,&a,&b,&p,&q)){
		ans=0;
		if(q>=p){
			ans+=n/b*q;
			for(i=a;i<=n;i+=a)
				if(i%b!=0)
					ans+=p;
		}
		else{
			ans+=n/a*p;
			for(i=b;i<=n;i+=b)
				if(i%a!=0)
					ans+=q;
		}
		printf("%I64d\n",ans);
	}
	return 0;
}

#include<stdio.h>
#include<stdint.h>
int main()
{
    int64_t n,a,b,p,q,c,d,i,sum;
    while(scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q)==5){
            sum=0;
        if(p>q||p==q){
            c=n/a;
            sum=c*p;
            if(a>b){
                for(i=a*2;i<n;i+=a){
                if(i%b==0){
                    break;
                }
            }
            }
            else{
                for(i=b*2;i<n;i+=b){
                if(i%a==0){
                    break;
                }
            }
            }

            d=n/b-n/i;
            sum+=d*q;
        }

        else{
            c=n/b;
            sum=c*q;
            if(a>b){
                for(i=a*2;i<n;i+=a){
                if(i%b==0){
                    break;
                }
            }
            }
            else{
                for(i=b*2;i<n;i+=b){
                if(i%a==0){
                    break;
                }
            }
            }
            d=n/a-n/i;
            sum+=d*p;
        }
        printf("%I64d\n",sum);
    }

    return 0;
}

#include<stdio.h>
#include<stdint.h>
int main()
{
    int64_t n,a,b,p,q,c,d,i,sum;
    while(scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q)==5){
            sum=0;
        if(p>q||p==q){
            c=n/a;
            sum=c*p;
            if(a>b){
                for(i=a*2;i<n;i+=a){
                if(i%b==0){
                    break;
                }
            }
            d=n/b-n/i;
            sum+=d*q;
            }
            else if(a==b){
                sum=sum;
            }

            else{
                for(i=b*2;i<n;i+=b){
                if(i%a==0){
                    break;
                }
            }

            }
        }

        else{
            c=n/b;
            sum=c*q;
            if(a>b){
                for(i=a*2;i<n;i+=a){
                if(i%b==0){
                    break;
                }
            }
            d=n/b-n/i;
            sum+=d*q;
            }
             else if(a==b){
                sum=sum;
            }
            else{
                for(i=b*2;i<n;i+=b){
                if(i%a==0){
                    break;
                }
            }
            d=n/b-n/i;
            sum+=d*q;
            }
        }
        printf("%I64d\n",sum);
    }

    return 0;
}

#include<stdio.h>
#include<stdint.h>
int main()
{
    int64_t n,a,b,p,q,c,d,i,sum;
    while(scanf("%I64d %I64d %I64d %I64d %I64d",&n,&a,&b,&p,&q)==5){
            sum=0;
        if(p>q){
            c=n/a;
            sum=c*p;
            for(i=b;i<n;i+=b){
                if(i%a==0){
                    break;
                }
            }
            d=n/b-n/i;
            sum+=d*q;
        }
        else{
            c=n/b;
            sum=c*q;
            for(i=a;i<n;i+=a){
                if(i%b==0){
                    break;
                }
            }
            d=n/a-n/i;
            sum+=d*p;
        }
        printf("%I64d\n",sum);
    }

    return 0;
}

#include<stdio.h>
int main()
{
          long long n,i,a,b,p,q,sum=0;
          scanf("%I64d%I64d%I64d%I64d%I64d",&n,&a,&b,&p,&q);
          for(i=1;i<=n;i++)
          {
                    if(i%a==0)
                    sum=sum+p;
                    else if(i%b==0)
                    sum=sum+q;
          }
          printf("%I64d",sum);
          return 0;
}