Roy and Wobbly Numbers
Practice
3.7 (23 votes)
Ad Hoc
Mathematics
Open
Approved
Easy
Mathamatics
Problem
42% Success 7004 Attempts 20 Points 5s Time Limit 256MB Memory 1024 KB Max Code

Roy is looking for Wobbly Numbers.

An N-length wobbly number is of the form "ababababab..." and so on of length N, where \(a != b\).

A 3-length wobbly number would be of form "aba".
Eg: \(101, 121, 131, 252, 646\) etc
But \(111, 222, 999\) etc are not 3-length wobbly number, because here \(a != b\) condition is not satisfied.
Also \(010\) is not a 3-length wobbly number because it has preceding 0. So \(010\) equals \(10\) and \(10\) is not a 3-length wobbly number.

A 4-length wobbly number would be of form "abab".
Eg: \(2323, 3232, 9090, 1414\) etc

Similarly we can form a list of N-length wobbly numbers.

Now your task is to find K\(th\) wobbly number from a lexicographically sorted list of N-length wobbly numbers. If the number does not exist print 1 else print the Kth wobbly number. See the sample test case and explanation for more clarity.

Input:
First line contains T - number of test cases
Each of the next T lines contains two space separated integers - N and K.

Output:
For each test case print the required output in a new line.

Constraints:
\(1 ≤ T ≤ 100\)
\(3 ≤ N ≤ 1000\)
\(1 ≤ K ≤ 100\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
99 votes
Tags:
Ad-HocBasic MathEasy簡単MathematicsMathematics
Points:20
Tags:
Easy
Points:20
5 votes
Tags:
EasyNumber Theory