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> ...
随机推荐
- LitJson JavaScriptSerializer
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- bmp和Variant的转换
procedure TForm2.VariantToBMP(aValue : OleVariant;var aBmp:TBitmap); var Stream : TMemoryStream; ...
- Typora快捷键的使用
无序列表:输入-之后输入空格 有序列表:输入数字+“.”之后输入空格 任务列表:-[空格]空格 文字 标题:ctrl+数字 表格:ctrl+t 生成目录:[TOC]按回车 选中一整行:ctrl+l 选 ...
- new operator
[new operator] When the code new Foo(...) is executed, the following things happen: A new object is ...
- PR数量回写重复
- python,遍历文件的方法
在做验证码识别时,识别时需要和库里的图片对比,找到最接近的那个图片,然后就行到了用与图片一致的字符命名,获取文件的名称,去将图片的名称读出来作为验证码.以下是我通过网上的资料总结的三种文件遍历的方式, ...
- Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers http://poj.org/problem?id=2739 Time Limit: 1000MS Memory Limit: 6 ...
- 33. Search in Rotated Sorted Array旋转数组二分法查询
一句话思路:反正只是寻找一个最小区间,断开也能二分.根据m第一次的落点,来分情况讨论. 一刷报错: 结构上有根本性错误:应该是while里面包括if,不然会把代码重复写两遍,不好. //situati ...
- 【转】MEF程序设计指南四:使用MEF声明导出(Exports)与导入(Imports)
在MEF中,使用[System.ComponentModel.Composition.ExportAttribute]支持多种级别的导出部件配置,包括类.字段.属性以及方法级别的导出部件,通过查看Ex ...
- ubuntu查找命令比较
1. find find是最常见和最强大的查找命令,你可以用它找到任何你想找的文件. find的使用格式如下: $ find <指定目录> <指定条件> < ...