Comments

My solution for B question has complexity O( k * (log(2 * 10^7)[base 9]) * 10 ).

Source code: link

Is this the optimized one that you are talking about @jinlifu1999