### Loser_'s blog

By Loser_, history, 17 months ago,

hello I am stuck in this problem Digit Queries.I think I need to use recursion here although not quite sure how? Which algo or technique I need to study to solve this problem? Also please share similar types of problems from other ojs.Please help me with that.

• -2

 » 17 months ago, # |   0 simple constructive algorithms is enough to solve this
 » 17 months ago, # | ← Rev. 3 →   0 This string contains numbers, numbers contain digits.Note: summary length of all n-digit numbers is easy to calculate. more detailed solutionSo you firstly brute force the length(L) of number, where your digit took place. Also this sum grows fast, so L < 18, so L-digit number fits in 64-bit numbers.Then you have position of first L-digit number. Now it's easy to find in what L-digit number your digit is.Then you have L-digit number and position of digit, you just output this digit of L-digit number.
•  » » 15 months ago, # ^ | ← Rev. 2 →   0 Thanks
 » 15 months ago, # | ← Rev. 2 →   0 Hello, I try to solve this problem https://cses.fi/problemset/task/2431/ I come up with a formuler: x is length of number (1,2,3,4) k = 9*1 + 90*2 + 900*3 + 9000*4 +..+9*(10^x)*x : total number here my code: https://cses.fi/paste/f1e04f128ac4fe471ae4e1/ however, my code passed only two first test cases. I don't know what wrong with my code. Here are test cases' resultPlease help me to point what's wrong. thank you.
•  » » 11 months ago, # ^ | ← Rev. 2 →   0 I use c++ and i had same problem(1st 2 test cases were passed but other 2 gave error) the thing is dont use inbuilt math functions as you used pow function(build your own pow function instead of using inbuilt pow function, then all test cases get satisfied).Here's the code i used https://onlinegdb.com/fnTAINkFb moral of story: dont use/avoid in built math functions
•  » » » 9 months ago, # ^ |   0 Or just use them properly. pow is not meant to be used for integers, it's meant to be used for doubles. There are plenty of built in math functions that are very useful, you just have to use the right ones.
•  » » 8 months ago, # ^ |   0 Here is a solution that uses similar logic and passes all tests: Codeimport math q = int(input()) for i in range(q): k = int(input()) i = 1 l = 0 while l + i * 9 * pow(10, i-1) < k: l += i * 9 * pow(10, i-1) i += 1 k -= l n = pow(10, i-1) str_len = math.floor(math.log10(n)) + 1 n = int(n + k // str_len) k = math.floor(k % str_len) - 1 if k < 0: n -= 1 s = str(n) print(s[k]) 
 » 15 months ago, # | ← Rev. 2 →   0 this problem is same as Digits Sequence
•  » » 15 months ago, # ^ |   0 thank you
•  » » 15 months ago, # ^ |   0 I've submitted the same code as on cses.fi and it worked!. I don't know why it fails on cses.https://codeforces.com/contest/1177/submission/108590612
 » 15 months ago, # |   0 Good Constructive Algorithm question! Here is my descriptive solution (https://ideone.com/4yYbq4)
•  » » 15 months ago, # ^ |   0 Thank you!
 » 13 months ago, # |   0 you can find a complete video editorial of that problem here: https://youtu.be/QAcH8qD9Pe0