CodeForces 483B Friends and Presents
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.
In addition, the first friend does not like the numbers that are divisible without remainder by prime number x. The second one does not like the numbers that are divisible without remainder by prime number y. Of course, you're not going to present your friends numbers they don't like.
Your task is to find such minimum number v, that you can form presents using numbers from a set 1, 2, ..., v. Of course you may choose not to present some numbers at all.
A positive integer number greater than 1 is called prime if it has no positive divisors other than 1 and itself.
Input
The only line contains four positive integers cnt1, cnt2, x, y (1 ≤ cnt1, cnt2 < 109; cnt1 + cnt2 ≤ 109; 2 ≤ x < y ≤ 3·104) — the numbers that are described in the statement. It is guaranteed that numbers x, y are prime.
Output
Print a single integer — the answer to the problem.
Sample Input
3 1 2 3
5
1 3 2 3
4
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std; typedef long long LL;
LL cnt1, cnt2, x, y; bool check(LL v)
{
LL f1,f2,both,others,ff1,ff2,gf1,gf2;
f1 = v / x;
f2 = v / y;
both = v / (x*y);
others = v - f1 - f2 + both;
ff1 = f1 - both;
ff2 = f2 - both; gf1 = (cnt1 - ff2 >= ? cnt1 - ff2 : );
gf2 = (cnt2 - ff1 >= ? cnt2 - ff1 : ); return (gf1 + gf2 <= others);
} int main()
{
while (scanf("%I64d%I64d%I64d%I64d", &cnt1, &cnt2, &x, &y) != EOF)
{
LL l=, r=1e18;
while (l<r)
{
LL m=(l+r)/;
if (check(m))
r=m;
else
l=m+;
}
printf("%I64d\n",r);
}
return ;
}
CodeForces 483B Friends and Presents的更多相关文章
- Codeforces 483B - Friends and Presents(二分+容斥)
483B - Friends and Presents 思路:这个博客写的不错:http://www.cnblogs.com/windysai/p/4058235.html 代码: #include& ...
- codeforces 483B Friends and Presents 解题报告
题目链接:http://codeforces.com/problemset/problem/483/B 题目意思:有两个 friends,需要将 cnt1 个不能整除 x 的数分给第一个friend, ...
- 【codeforces 483B】Friends and Presents
[链接] 我是链接,点我呀:) [题意] [题解] 我们可以二分n的值,设为mid 那么对于n=mid 我们可以算出来以下3个东西 temp1 = n/x; temp2 = n/y; temp3 = ...
- CF 483B. Friends and Presents 数学 (二分) 难度:1
B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input stand ...
- CodeForces 483B 二分答案
题目: B. Friends and Presents time limit per test 1 second memory limit per test 256 megabytes input s ...
- codeforces B. Friends and Presents(二分+容斥)
题意:从1....v这些数中找到c1个数不能被x整除,c2个数不能被y整除! 并且这c1个数和这c2个数没有相同的!给定c1, c2, x, y, 求最小的v的值! 思路: 二分+容斥,二分找到v的值 ...
- codeforces 466C 计数 codeforces 483B 二分 容斥
题意:给你n个数,将他们分成连续的三个部分使得每个部分的和相同,求出分法的种数. 思路:用一个数组a[i]记下从第一个点到当前i点的总和.最后一个点是总和为sum的点,只需求出总和为1/3sum的点和 ...
- codeforces483B
Friends and Presents CodeForces - 483B You have two friends. You want to present each of them severa ...
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A. Little Artem and Presents 水题
A. Little Artem and Presents 题目连接: http://www.codeforces.com/contest/669/problem/A Description Littl ...
随机推荐
- 夺命雷公狗---2016-linux---3之目录一般作用
最好文件还是存放在自己的home目录下 建议:在很多时候如果需要系统备份最好去备份boot和etc这两个目录
- ssh & display
在Windows下用ssh连接服务器的话putty是一个小巧而且实用的工具,如果想要图形界面,可以使用X工具配合putty. 或者直接使用xmanager enterprise,非 常方便. 如果在U ...
- archlinux安装输入法需要的包及archlinux无法使用输入法的解决
所需的包: fcitx #这货应该是主要的程序 fcitx-configtool #图形化的配置工具,非必须 fcitx-gtk2 fcitx-gtk3 fcitx-qt4 fcitx-qt5 fci ...
- [转载] 关关采集不能生成html的问题
转载地址:http://www.pcliver.com/archives/814.html 关关不能生成html的问题: 1.关关设置的问题 2.模板标签关关不支持 排除法之后,得出我的网站是模板的问 ...
- 第三方过滤器在TVideoGrabber中的使用
在TVideoGrabber中可以使用第三方过滤器,并可插入到预览.录制或回放流中,添加到列表里. 要在一个图像中中应用一个过滤器,需要像下面的例子中一样调用 ThirdPartyFilter_Add ...
- 鸟哥的linux私房菜学习记录之例行性工作
- msyql数据库位置
MySQL默认的数据文件存储目录为/var/lib/mysql.假如要把目录移到/home/data下需要进行下面几步: 1.home目录下建立data目录 cd /home mkdir data 2 ...
- 160908、前端开发框架Semantic UI
简介 网页开发中,CSS控制网页样式.作为测试开发工程师,我个人不太擅长手写CSS.样式微调.兼容浏览器等工作,所以我选择使用成熟的前端框架,可以快速开发出样式美观的网站,也解决了大部分浏览器兼容问题 ...
- LUA笔记之字符串
LUA提供了自动数值转换, 基本上说是乱来也不为过, 就当做是不熟悉数据结构吧, 例子: print("10" + 1) --> 11 print("10 + 1& ...
- word2007里插入分节符
1.打开Word文档,将鼠标定位到需要插入分页符的位置(比如第2页的末尾处),切换到"页面布局"功能区. 2.在"页面设置"分组中单击"分隔符&quo ...