728x90
#if 1
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <unordered_map>
#include <cmath>
#define ll long long
#define ull unsigned long long
using namespace std;
int N, K;
ull low, high, ans;
int getStand(int n)
{
int ret = 0;
while (n > 0) n /= 10, ret++;
return ret;
}
ull getLen(int n)
{
int len = getStand(n);
ull ret = 0;
while (len > 0)
{
int tmp = n - pow(10, len - 1) + 1;
ret += len * tmp;
n -= tmp;
len--;
}
return (ret);
}
int main(void)
{
//ios_base::sync_with_stdio(false);
//cin.tie(nullptr);
//cout.tie(nullptr);
freopen("input.txt", "r", stdin);
cin >> N >> K;
low = 1;
high = N;
ull len = getLen(N);
if (len < K) {
cout << -1 << '\n';
return 0;
}
while (low <= high)
{
ull mid = (low + high) / 2;
len = getLen(mid);
if (len < K) low = mid + 1;
else ans = mid, high = mid - 1;
}
char buf[20];
int s = sprintf(buf, "%d", ans);
len = getLen(ans);
cout<< buf[s - (len - K) - 1] - '0'<<'\n';
}
#endif
728x90
'알고리즘, PS, 문제풀기등 > 2) 탐색 알고리즘(DFS, BFS, 이진 탐색)' 카테고리의 다른 글
숫자구슬(정올) / 백준 숫자구슬(2613) - 이분탐색 (0) | 2023.02.07 |
---|