Even Pair Sum[EVENPSUM](Solution)

AKSHAT KUMAR JAIN
2 min readDec 15, 2020

--

You are given two positive integers A and B. Find the number of pairs of positive integers (X,Y) such that 1≤X≤A, 1≤Y≤B and X+Y is even.

Input

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first and only line of each test case contains two space-separated integers A and B.

Output

For each test case, print a single line containing one integer ― the number of valid pairs.

Constraints

  • 1≤T≤1,000
  • 1≤A,B≤10⁹

Subtasks

Subtask #1 (10 points): A,B≤10

Subtask #2 (10 points): A,B≤1,000

Subtask #3 (80 points): original constraints

Example Input

4
1 1
2 3
4 6
8 9

Example Output

1
3
12
36

SOLUTION

#include <iostream>
using namespace std;
# define ll long long int
int
main ()
{
// your code goes here
ll t, a, b;
cin >> t;
while (t--)
{
cin >> a >> b;
ll even_a, odd_a, even_b, odd_b;
even_a = a / 2;
odd_a = a - even_a;
even_b = b / 2;
odd_b = b - even_b;
cout<< even_a * even_b + odd_a * odd_b << "\n" ;}
return 0;
}

LINK OF SOLUTION:

SUPPORT ME ON:

GET IN TOUCH WITH ME:

--

--