Palindrome numbers

3.5

25 votes
Binary Search, Math Basic, Algorithms, Basic Math, Math
Problem

A palindromic number is a number that remains the same when its digits are reversed. Your task is to get the \(k^{th}\) palindrome number greater than or equal to \(X\).

Input format

  • First line: Integer \(T\) denoting the number of test cases
  • Each of the following \(T\) lines:
    •  First line: Two space-separated integers \(X\) and \(K\)

Output format

Print \(T\) lines, each line contains the answer for the \(i^{th}\) case.

Constraints

\(1 \leq X,\ K \leq 10^9\)

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The first 32 palindrome numbers are:\(1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121, 131, 141, 151, 161, 171, 181, 191, 202, 212, 222, 232.\)

Editor Image

?