# 14. 员工派遣
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.on('line', (line) => {
const [x,y,cntX,cntY] = line.split(' ').map(Number);
let minId = cntX + cntY;
let maxId = 1000000000;
while(minId <= maxId) {
const midId = Math.floor((maxId + minId)/2);
const excludedX = Math.floor(midId/x);
const excludedY = Math.floor(midId/y);
const needx = Math.max(0, cntX - (excludedY - excludedBoth));
const needy = Math.max(0, cntY - (excludedX - excludedBoth));
const excludedBoth = Math.floor(midId/(x*y));
const total = midId - excludedX - excludedY + excludedBoth;
if (needx + needy <= total) {
maxId = midId - 1;
} else {
minId = midId + 1;
}
}
console.log(minId);
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
← 13. 反射计数 15. 图像物体的边界 →