302501: CF483B. Friends and Presents

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Friends and Presents

题意翻译

找到一个最小的$V$,从$1…V$中选$cnt_1$个数给A,选$cnt_2$个数给B。A不要$x$的倍数,B不要$y$的倍数。$x,y$为质数。一个数不能同时给A、B。

题目描述

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.

输入输出格式

输入格式


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.

输出格式


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 $ .

Input

题意翻译

找到一个最小的$V$,从$1…V$中选$cnt_1$个数给A,选$cnt_2$个数给B。A不要$x$的倍数,B不要$y$的倍数。$x,y$为质数。一个数不能同时给A、B。

加入题单

算法标签: