[Solution] No Palindrome CodeChef Solution 2023
Problem
Given positive integers and , let denote the smallest number of digits (with no leading zeros) such that:
- No substring of having length strictly greater than is a palindrome.
Find the sum of digits of .
Note:
- A substring of a number is obtained by deleting some (possibly zero) digits from the beginning of the number and some (possibly zero) digits from the end of the number. For example, some substrings of the number are and .
- Leading zeros are considered in a substring. In the above example, and are valid substrings.
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of two space-separated integers and — as mentioned in the statement.
Output Format
For each test case, output on a new line, the sum of digits of the smallest number of digits satisfying the given condition.
Explanation:
Test case : The smallest number of digits satisfying the condition is . Here no substring of length greater than is a palindrome.
Test case : The smallest number of digits satisfying the condition is . The sum of its digits is .
No comments:
Post a Comment