题解:
容斥定理。
#include<bits/stdc++.h>
#define int long long
using namespace std;
int lcm(int a,int b)
{
return a*b/__gcd(a,b);
}
void solve()
{
int n,a,b,p,q; cin>>n>>a>>b>>p>>q;
cout<<n/a*p+n/b*q-min(p,q)*(n/lcm(a,b))<<'\n';
}
signed main()
{
solve();
return 0;
}