[Solution] Fit in Data Type solution codechef

Fit in Data Type solution codechef – Chef wants to store some important numerical data on his personal computer. He is using a new data type that can store values only from 00 till NN both inclusive. If this data type receives a value greater than NN then it is cyclically converted to fit into the range 00 to NN. For example:

  • Value N+1N+1 will be stored as 00.
  • Value N+2N+2 will be stored as 11.

and so on…

Given XX, the value chef wants to store in this new data type. Determine what will be the actual value in memory after storing XX.

Fit in Data Type solution codechef

  • First line will contain TT, number of testcases. Then the testcases follow.
  • Each testcase contains a single line of input, two space separated integers N,XN,X – the maximum value a data type can store and the value Chef wants to store in the data type respectively.

Output Format

For each testcase, output in a single line the value which will be actually stored in memory.

Constraints

  • 1T30001≤T≤3000
  • 1N501≤N≤50
  • 0X500≤X≤50

Sample Input 1 

5
15 0
15 10
11 12
27 37
50 49

Fit in Data Type solution codechef

 

0
10
0
9
49

Explanation

Test Case 11: The data type can store values from 00 to 1515. If we try to put 00 in this data type, then the stored value will be the same, that is 00.

Test Case 22: The data type can store values from 00 to 1515. If we try to put 1010 in this data type, then the stored value will be the same, that is 1010.

Test Case 33: The data type can store values from 00 to 1111. If we try to put 1212 in this data type, then the stored value will cyclically come back to 00. Hence the output is 00.

Test Case 44: The data type can store values from 00 to 2727. If we try to put 3737 in this data type, then the stored value will cyclically convert to 99. Hence the output is 99.

Leave a Comment