#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #ifdef local #include #else #define dump(...) void(0); #endif #include #include #include #include namespace man { } int main() { std::cin.tie(nullptr) -> sync_with_stdio(false); std::string n; int64_t k; std::cin >> n >> k; const auto sol = [&](const std::string &t) -> std::string { int64_t now = 1; std::string s; for(const auto &e: t | std::views::reverse) { const int f = e - '0' + 1; if(now * f >= k) { for(const auto &i: std::views::iota(0, f)) { if(now + i == k) { s += i + '0'; std::ranges::reverse(s); return s; } } } now *= f; s += e; } return s; }; std::cout << sol(n) << '\n'; }