Wesley's Anger Contest Reject 2 - 🥕suba

View as PDF

Submit solution


Points: 3
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Recently, Tesley has been learning about polynomials, and since her friends always throw around the term "🥕suba", she would like to learn more about it.

Tesley wants to know how many terms the resulting polynomial will have if she multiplies two polynomials that have A and B terms, respectively. A polynomial is an expression consisting of variables and coefficients, but to keep things simple, Tesley will only deal with polynomials where the coefficient of each term is 1, and the polynomial will be the lowest degree possible while ensuring that it has the number of terms specified.

For example x^3 + x^2 + x + 1 is a valid polynomial for 4 terms, while x^2 + 1 and 2x^2 + 3x + 1 are not valid polynomials for 2 and 3 terms respectively.

Can you help Tesley determine the number of terms in the resulting polynomial after they are multiplied together?

Constraints

For this problem, you will be required to pass all the samples in order to receive points.

1 \le T \le 1\,000
1 \le A,B \le 1\,000\,000

Input Specification

The first line will contain T, the number of test cases.

The second line will contain two space-separated integers A and B, the number of terms in the first and second polynomials, respectively.

Output Specification

This problem is graded with an identical checker. This includes whitespace characters. Ensure that every line of output is terminated with a \n character and that there are no trailing spaces.

Output T lines. On the i^\text{th} line, output the number of terms in the resulting polynomial for the i^\text{th} test case.

Sample Input 1

2
2 2
3 4

Sample Output 1

3
6

Sample Explanation 1

For the first test case,

There are two polynomials with two terms, x+1 and x+1, when multiplied together becomes x^2 + 2x + 1.

For the second test case,

There are two polynomials with degree 2 and 3, x^2 + x + 1 and x^3 + x^2 + x + 1, when multiplied together becomes x^5 + 2x^4 + 3x^3 + 3x^2 + 2x + 1.


Comments

There are no comments at the moment.