CodeChef May Long Challenge Solution | Modular Equation (MODEQ) solution | AskTheCode
Problem:
Given integers N and M, find the number of ordered pairs (a,b) such that 1≤a<b≤N and ((Mmoda)modb) = ((Mmodb)moda).
Input:
The first line contains an integer T, the number of test cases. Then the test cases follow.
The only line of each test case contains two integers N, M.
Output:
For each testcase, output in a single line the answer to the problem.
Sample Input:
3
3 5
3 6
3 10
Sample Output:
2
3
2
Explanation:
Test Case 1: The valid pairs are {(1,2),(1,3)}.
Test Case 2: The valid pairs are {(1,2),(1,3),(2,3)}.
Test Case 3: The valid pairs are {(1,2),(1,3)}.
Code:
The solution is there in AskTheCode Members Group. Visit there and grab your required solution, click here to redirect there. This is a private segment only for members, so if you are new here, please do join first then head towards the solution.
Comments