CF483B.Friends and Presents

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have two friends. You want to present each of them several positive integers. You want to present _cnt_1 numbers to the first friend and _cnt_2 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.

你有两个朋友。你想分别送给他们若干个正整数:送给第一个朋友 _cnt_1 个数,送给第二个朋友 _cnt_2 个数。此外,所有送出的数必须互不相同,即不能有任何一个数同时送给两个朋友。

另外,第一个朋友不喜欢能被素数 x 整除的数;第二个朋友不喜欢能被素数 y 整除的数。显然,你不会把朋友不喜欢的数送给他们。

你的任务是找出最小的正整数 v,使得你可以仅从集合 {1, 2, …, v}\{1,\,2,\,\dots,\,v\} 中选取数字来完成上述送礼要求(当然,你也可以选择不使用集合中的某些数字)。

大于 1 的正整数若除了 1 和它自身之外没有其他正因数,则称为素数。

输入格式

The only line contains four positive integers _cnt_1, _cnt_2, x, y (1 ≤ _cnt_1, _cnt_2 < 109; _cnt_1 + _cnt_2 ≤ 109; 2 ≤ x < y ≤ 3·104) — the numbers that are described in the statement. It is guaranteed that numbers x, y are prime.

唯一的一行包含四个正整数 cnt1cnt_1、cnt2cnt_2、xx、yy(1 ≤ cnt1, cnt2 < 1091 ≤ cnt_1, cnt_2 < 10^9;cnt1 + cnt2 ≤ 109cnt_1 + cnt_2 ≤ 10^9;2 ≤ x < y ≤ 3⋅1042 ≤ x < y ≤ 3·10^4),这些数在题面中已作描述。保证 xx、yy 均为质数。

输出格式

Print a single integer — the answer to the problem.

输出一个整数——该问题的答案。

输入输出样例

  • 输入#1

    3 1 2 3

    输出#1

    5
  • 输入#2

    1 3 2 3

    输出#2

    4

说明/提示

In the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend.

In the second sample you give the set of numbers {3} to the first friend, and the set of numbers {1, 2, 4} to the second friend. Thus, the answer to the problem is 4.

在第一个样例中,你将数字集合 {1, 3, 5}\{1,\,3,\,5\} 给了第一位朋友,将数字集合 {2}\{2\} 给了第二位朋友。注意:如果你将集合 {1, 3, 5}\{1,\,3,\,5\} 给了第一位朋友,那么我们就不能将数字 11、33、55 中的任何一个给第二位朋友。

在第二个样例中,你将数字集合 {3}\{3\} 给了第一位朋友,将数字集合 {1, 2, 4}\{1,\,2,\,4\} 给了第二位朋友。因此,该问题的答案为 44。

输入解题思路,AI测评打分。不知道怎么写?

首页