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