codeforces 678C. Joty and Chocolate(容斥) 2016-10-15 21:49 122人阅读 评论(0) 收藏
1 second
256 megabytes
standard input
standard output
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
题目的意思是给你1-n,n个数,你可以把a的倍数染成红色获得p价值,把b的倍数染成蓝色获得q价值,a,b公倍数任意一种颜色问最大价值
直接把a的倍数的和b的倍数的价值全加起来,公倍数染价值大的,即减去小的价值的即可
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
#define inf 0x3f3f3f3f long long gcd(long long x,long long y){
if(y==0) return x;
else return(gcd(y,x%y));
} long long lcm(long long x,long long y){
return x*y/gcd(x,y);
} int main()
{
long long n,a,b,p,q;
while(~scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&p,&q))
{
long long lm=lcm(a,b);
printf("%lld\n",(n/a)*p+(n/b)*q-min(p,q)*(n/(lm))); }
return 0;
}
codeforces 678C. Joty and Chocolate(容斥) 2016-10-15 21:49 122人阅读 评论(0) 收藏的更多相关文章
- Codeforces 632D Longest Subsequence 2016-09-28 21:29 37人阅读 评论(0) 收藏
D. Longest Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces 766D Mahmoud and a Dictionary 2017-02-21 14:03 107人阅读 评论(0) 收藏
D. Mahmoud and a Dictionary time limit per test 4 seconds memory limit per test 256 megabytes input ...
- hadoop容灾能力测试 分类: A1_HADOOP 2015-03-02 09:38 291人阅读 评论(0) 收藏
实验简单来讲就是 1. put 一个600M文件,分散3个replica x 9个block 共18个blocks到4个datanode 2. 我关掉了两个datanode,使得大部分的block只在 ...
- Codeforces 343D Water Tree 分类: Brush Mode 2014-10-05 14:38 98人阅读 评论(0) 收藏
Mad scientist Mike has constructed a rooted tree, which consists of n vertices. Each vertex is a res ...
- codeforces 702C Cellular Network 2016-10-15 18:19 104人阅读 评论(0) 收藏
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 706C Hard problem 2016-09-28 19:47 90人阅读 评论(0) 收藏
C. Hard problem time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- Codeforces 768A Oath of the Night's Watch 2017-02-21 22:13 39人阅读 评论(0) 收藏
A. Oath of the Night's Watch time limit per test 2 seconds memory limit per test 256 megabytes input ...
- Codeforces 766C Mahmoud and a Message 2017-02-21 13:57 62人阅读 评论(0) 收藏
C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- CodeForces 678C Joty and Chocolate
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
随机推荐
- Haskell语言学习笔记(55)Data.Vector
Data.Vector Construction Prelude V> import Data.Vector as V Prelude V> V.empty [] Prelude V> ...
- centos7 莫名重起的问题
ausearch -i -m system_boot,system_shutdown | tail -4----type=SYSTEM_BOOT msg=audit(2018年05月10日 07:45 ...
- mesos无执行器启动docker
生成taskInfo task = mesos_pb2.TaskInfo() task_id = name task.task_id.value = task_id task.slave_id.val ...
- 安装Anaconda以及jupyter的使用
1)下载https://www.anaconda.com/download/ 2)安装 3)终端查看(Anaconda Prompt) 4)升级所有的包 初次安装下的软件包版本一般都比较老旧,因此提前 ...
- Android使用HTTPS进行IP直连握手失败问题(okHttp)
为什么要使用ip直连这种方式去请求我们的服务器呢?这其实和国内运营伤有关,运营商有时为了利益会将你的域名劫持换成他人的域名,为了防止这种情况的发生通用的解决办法要么联系运营商要么就只能使用ip直连了. ...
- 重新认识trim,ltrim,rtrim,trailing和leading。
trim经常用来去除一个字符串的空格,select trim(' dhajkjwa ') from dual; 在上面的语句中,trim的前面也可以加r或者l,表示去掉前面或者后面的空格,r和l代表左 ...
- Django的admin介绍
我们看到我们创建一个默认的django的项目,他在project的urls有一个admin的url的路径 我们访问这个路径,他是一个登陆框,需要输入用户名和密码 我们就需要创建这个用户名和密码,如果你 ...
- 找峰值I II · Find Peak Element I ii
一句话思路:找最大的元素.没有target? 一刷报错: 一定要用二分,否则复杂度不是最优. 判断条件是nums[mid] < nums[mid + 1],还是基于中位数比较的原理.不是nums ...
- Java 架构师
“学习的最好途径就是看书“,这是我自己学习并且小有了一定的积累之后的第一体会.个人认为看书有两点好处: 1.能出版出来的书一定是经过反复的思考.雕琢和审核的,因此从专业性的角度来说,一本好书的价值远超 ...
- java的PDF纵横向打印
PDF默认是纵向打印的,通过rotate()来让其改变为横向打印,一般在打印A4 12*21纸以及发票的时候会用横向打印.横向打印时页面会出现行转列以及列转行的情况,因此在设置页面大小的时候一定要宽度 ...