Description

Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern.

An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if it's index is divisible byb. So the tile with the number divisible by a and b can be either painted Red or Blue.

After her painting is done, she will get p chocolates for each tile that is painted Red and q chocolates for each tile that is painted Blue.

Note that she can paint tiles in any order she wants.

Given the required information, find the maximum number of chocolates Joty can get.

Input

The only line contains five integers nabp and q (1 ≤ n, a, b, p, q ≤ 109).

Output

Print the only integer s — the maximum number of chocolates Joty can get.

Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

Examples
input
5 2 3 12 15
output
39
input
20 2 3 3 5
output
51
一个简单的容斥,我们先算a再算b,再求能被a和b一起整除的,然后算出单独被a,b整除的,一起整除的我们选最大的去乘
 #include <iostream>
#include <stdio.h>
#include <string.h>
#include<algorithm>
using namespace std;
int main()
{
long long n,a,b,p,q;
long long ans1,ans2,ans3,ans4,ans5;
cin>>n>>a>>b>>p>>q;
ans1=n/a;ans2=n/b;ans3=a/__gcd(a,b)*b;ans4=n/ans3;
cout<<(ans1-ans4)*p+(ans2-ans4)*q+ans4*max(p,q)<<endl;
return ;
}

最新文章

  1. mongogogog
  2. paip.语义分析--分词--常见的单音节字词 2_deDuli 单字词 774个
  3. apply与call
  4. Android通过URL加载网络图片
  5. 我的android学习经历24
  6. HDU 3480 division
  7. jqure获取单选按钮的值(比如性别)
  8. CentOS&amp;nbsp;6.4&amp;nbsp;图文安装教…
  9. django: db - many to one
  10. angularjs jsonp跨域
  11. 【Jquery】之DOM操作
  12. IDEA 使用tomcat7-maven-plugin
  13. CentOS7切换源
  14. Docker 镜像编排并部署SpringBoot应用
  15. Android5.0新特性之——按钮点击效果动画(涟漪效果)
  16. react 中的绑定事件
  17. 费马大定理以及求解a^2+b^2=c^2的奇偶数列法则
  18. mysql update受影响的行数为0或查询结果为空时
  19. TexturePacker的plist切成单独小图片
  20. jenkins自动构建部署

热门文章

  1. python爬虫(2)--Urllib库的高级用法
  2. struct-config.xml配置文件的解析
  3. 前端学习笔记2017.6.12 CSS控制DIV
  4. Arduino Serial库的使用
  5. java内存模型和线程安全
  6. 100198H Royal Federation
  7. Luogu 4103 [HEOI2014]大工程
  8. $this-&gt;autoRender = false
  9. patch请求--501错误
  10. 解决批处理命令执行完毕后自动关闭cmd窗口方法