If N = 3 and M = 5, then { x = 1, y = 4 }, { x = 2, y = 3 }, { x = 3, y = 2 } are the pairs that satisfy the given conditions.
The first line contains a single integer ‘T’ denoting the number of test cases, then each test case follows
The first line of each testcase contains two integers ‘N’ and ‘M’.
For each test case print a single integer denoting the count of divisible pairs.
Output for each test case will be printed in a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 10
1 <= N, M <= 10^9
Time limit: 1 sec
We can create all pairs possible and check the condition of divisibility.
To create all the pairs, for each x in the range [1, N] iterate through all y in the range [1, M].
The steps are as follows :
We know ( x + y ) % 5 = ( (x%5) + (y%5) ) % 5.
Using this we can easily notice sum of x and y can only be divisible by 5 when:
Now simply we can count these values, multiply them and add them.
The steps are as follows: