Chef vs Bharat Codechef solution. July Challenge 2021.
Chef and his friend Bharat have decided to play the game "The Chefora Spell".
In the game, a positive integer (in decimal system) is considered a "Chefora" if the number of digits is odd and it satisfies the equation
where is the -th digit of from the left in -based indexing.
Let denote the -th smallest Chefora number.
They'll ask each other questions, where each question contains two integers and . The opponent then has to answer with
Bharat has answered all the questions right, and now it is Chef's turn. But since Chef fears that he could get some questions wrong, you have come to his rescue!
Input
- The first line contains an integer - the number of questions Bharat asks.
- Each of the next lines contains two integers and .
Sample Input
2
1 2
9 11
Sample Output
1
541416750
Explanation
For the first question:
For the second question:
Python Code:
Another simplified solution:
(TLE in 2nd test case)
Comments
Post a Comment