Hello, I've been trying to solve this problem 1811E - Living Sequence and i couldnt The problem states that we want to delete all numbers that contain 4 as a digit and then find what is the number is position k . i read the editorial and i have a question,if you didnt solve it and dont wana see solution, ignore this blog. . . . the solution says we want delete one digit the we have to convert number from base 10 to base 9 and then add every digit by one where this digit >= 4. why we add 1 for those digit and if i want delete like 2 digit (6, 7) then i have to convert number from base 10 to base 8 ? and increase every digit >= 6 or >= 7 by one ? i didnt understand i i tried to see some expalin on youtube but no one say why we add one.
thank you very much
imagine you need to give the 8th no. in the living sequence, the first 8 numbers would be 1, 2, 3, 5, 6, 7, 8, 9 (since 4 has to be removed). Notice how all the numbers that were smaller than 4 are the right place while the greater ones are shifted one place. That's why you need to add 1 if the digit >= 4.
Similarly if you have to erase 2 digits says 3 and 7 (not taking 6 and 7 that you asked because it would be simple), now for this system, the sequence would be: 1, 2, 4, 5, 6, 8, 9...... Notice how all the digits before 3 are at right place and the digits between 3 and 7 are shifted to 1 place whereas all the values greater than 7 are moved with 2 places, so you would need to 1 if the digits is greater than 3 and smaller than 7 and if the digit is greater or equal to 7 then you would have 2 to the digits.
it is clear now, thank you