classSolution { public: intfindKthNumber(int n, int k) { int ans = 1; for (k--; k > 0;) { longlong count = 0; for (longlong first = ans, second = ans + 1; first <= n; first *= 10,second *= 10) { count += min(1LL*n + 1, second) - first; } if (count <= k) { k -= count; ans += 1; } else { k--; ans *= 10; } } return ans; } }wc;