CF483B.Friends and Presents

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You have two friends. You want to present each of them several positive integers. You want to present cnt1cnt_{1} numbers to the first friend and cnt2cnt_{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 xx . The second one does not like the numbers that are divisible without remainder by prime number yy . Of course, you're not going to present your friends numbers they don't like.

Your task is to find such minimum number vv , that you can form presents using numbers from a set 1,2,...,v1,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 cnt1cnt_{1} numbers to the first friend and cnt2cnt_{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 xx . The second one does not like the numbers that are divisible without remainder by prime number yy . Of course, you're not going to present your friends numbers they don't like.

Your task is to find such minimum number vv , that you can form presents using numbers from a set 1,2,...,v1,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{1,3,5} to the first friend and the set of numbers 2{2} to the second friend. Note that if you give set 1,3,5{1,3,5} to the first friend, then we cannot give any of the numbers 11 , 33 , 55 to the second friend.

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

首页