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 ...
随机推荐
- zw版【转发·台湾nvp系列Delphi例程】HALCON BinThreshold
zw版[转发·台湾nvp系列Delphi例程]HALCON BinThreshold unit Unit1;interfaceuses Windows, Messages, SysUtils, Var ...
- 【python】标准库的大致认识
正如那句 Python 社区中很有名的话所说的:“battery included”,Python 的一大好处在于它有一套很有用的标准库(standard library).标准库是随着 Python ...
- CSS Reset / Normalize 如何进行样式重置
CSS Reset 过于激进,所有样式全部消除没有必要. 关键是保持各种浏览器的兼容,包括Bootstrap的CSS Reset也是走的这个路线. 线面这个就是后面一种思路的成果: http://ne ...
- Error while trying to retrieve text for error ORA-01019 的解决办法
这个问题涉及到 64 位的oracle服务, 和32位的客户端导致的问题. 环境如下: win8.1 + 64位oracle 11.1 做服务器, 客户端由于采用32位程序,不支持64位的oracle ...
- linux设备驱动归纳总结(二):模块的相关基础概念【转】
本文转载自:http://blog.chinaunix.net/uid-25014876-id-59415.html linux设备驱动归纳总结(二):模块的相关基础概念 系统平台:Ubuntu 10 ...
- JNI 概述【转】
本文转载自:http://wiki.jikexueyuan.com/project/jni-ndk-developer-guide/overview.html 相信很多做过 Java 或 Androi ...
- 【secureCRT】设置自动连接会话+设置自动连接上次使用的会话:
- TI CC2541的整体目标
1. App端会发送一定数量的byte过来蓝牙, 每2个byte是一个汉字的编码. 2. 拿到汉字编码之后, 统计字符数量, 然后通过SPI, 搜索编码 3. 收到的编码, 每个汉字字符有32个byt ...
- PHP自定义函数格式化json数据怎么调用?
<?php/*** Formats a JSON string for pretty printing** @param string $json The JSON to make pretty ...
- 怎样用PHP制作验证码呢?
生成验证码无非就那么几个步骤,首先是获取一个随机字符串,然后创建一个布画,将生成的字符串写到布画上,我们还可以在布画上画线画雪花,现在帖一段生成验证码的代码. 源代码: <?phpsession ...