On the explanation of the title
Description
Students in a class are making towers of blocks. Each student makes a (non-zero) tower by stacking pieces lengthwise on top of each other. n of the students use pieces made of two blocks and m of the students use pieces made of three blocks.(1.n Two bricks were used as a unit to stack bricks, m 3 bricks as a unit)
The students don't want to use too many blocks, but they also want to be unique, so no two students' towers may contain the same number of blocks.(2.n + m The total number of bricks used by students is not the same) Find the minimum height necessary for the tallest of the students' towers.(3.Find a stack so that it can be all n + m The highest number of bricks used by each student is recorded as Max,because Max It can be very large, so as long as the brick is slightly higher than the second height, so the minimum value when the maximum height is met is calculated.)
Input
The first line of the input contains two space-separated integers n and m (0≤n,m≤1000000, n+m>0)− the number of students using two-block pieces and the number of students using three-block pieces, respectively.
Output
Print a single integer, denoting the minimum possible height of the tallest tower.
Sample Input
1 3
Sample Output
9
HINT
In the first case, the student using two-block pieces can make a tower of height 4, and the students using three-block pieces can make towers of height 3, 6, and 9 blocks. The tallest tower has a height of 9 blocks.
Test sample explanation:
One student uses two bricks as a unit to stack bricks (the height of this student's stack can be 2, 4, 6, 8, 10... As long as there is no repeat height), three students use three bricks as a unit to stack bricks (the height of each student's stack can be 3, 6, 9, 12, 15..., as long as there is no repeat height), because a maximum height h is required, and H is the maximum height The minimum value in, so 3 students stack bricks with 3 bricks as a unit (the height of each student's stack here is 3, 6, 9), 1 student stack bricks with 2 bricks as a unit (take 2, 4, 8, all right), so the minimum height that meets the condition is 9.
Because every six numbers are the same, the topic requires a unique height, so it should be subtracted.
Refer to the blogger's link, thank you ~
[by code]
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <vector> #include <stack> #include <set> #include <algorithm> using namespace std; int main() { int a, b; while(scanf("%d%d",&a,&b) != EOF) { for(int i = 0 ; ;i ++) { if(i / 2 >= a && i /3 >= b && i / 2 + i / 3 -i / 6 >= a + b) { cout<<i<<endl; break; } } } return 0; }