Codeforces Round #275 (Div. 2)B——Friends and Presents
3199 단어 codeforces
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 test(s)
Input
3 1 2 3
Output
5
Input
1 3 2 3
Output
4
Note
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.
2점 답안을 하고 x와 y의 공배수를 빼고 x의 배수 개수를 두 번째 사람에게 주고 y의 배수 개수를 첫 번째 사람에게 주고 판단하면 된다. 시합할 때 2점의 상한선을 작게 쓰고 FST를 쓰면 순간 울고 기절한다.
#include <map>
#include <set>
#include <list>
#include <stack>
#include <vector>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
__int64 cnt1, cnt2, x, y;
while (~scanf("%I64d%I64d%I64d%I64d", &cnt1, &cnt2, &x, &y))
{
__int64 l, r, mid;
__int64 tmp, s1, s2, s3, z = x * y, tmp1, tmp2, ans = 0;
l = 1;
r = 2000000000;
while (l <= r)
{
tmp1 = cnt1;
tmp2 = cnt2;
mid = (l + r) / 2;
s1 = mid / x;
s2 = mid / y;
s3 = mid / z;
s1 -= s3;
s2 -= s3;
tmp = mid - s3;
tmp1 -= s2;
if (tmp1 < 0)
{
tmp1 = 0;
}
tmp -= s2;
tmp2 -= s1;
if (tmp2 < 0)
{
tmp2 = 0;
}
tmp -= s1;
if (tmp >= tmp1 + tmp2)
{
r = mid - 1;
ans = mid;
}
else
{
l = mid + 1;
}
}
printf("%I64d
", ans);
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Codeforces Round #715 Div. 2C The Sports Festival: 구간 DP전형구간 DP의 초전형. 이하, 0-indexed. 입력을 정렬하여 어디서나 시작하고 최적으로 좌우로 계속 유지하면 좋다는 것을 알 수 있습니다. {2000})$의 주문이 된다. 우선, 입력을 소트하여 n개의 요소를 $...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.