Frobenius coin problem
Submissions: 247   Accuracy: 43.72%   Difficulty: Basic   Marks: 1

Given two coins of denominations “X” and “Y” respectively, find the largest amount that cannot be obtained using these two coins (assuming infinite supply of coins) followed by the total number of such non obtainable amounts, if no such value exists print “NA”.

Input:

The first line of input contains an integer T denoting the number of test cases.
Each test case consist of two integers X and Y in a single line separated by a space.

Output:

Print an integer which represents largest amount that cannot be obtained using these two coins followed by another integer which represents the total number of such non obtainable amounts. If no such value exists print “NA”.

Constraints:
1 ≤ T ≤ 70
2 ≤ M ≤ 104
2 ≤ N ≤ 104

Example:
Input
2
2 5
5 10
Output
3 2
NA

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Ashutosh Kumar
Author: vaibhav2992

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.