https://www.acmicpc.net/problem/1790
#include<stdio.h>
#include<string.h>
#include <math.h>
static long count(long t){
long num=1;
for(int i=0;i<t;i++){
num*=10;
}
return num;
}
int main() {
int n,k;
scanf("%d %d",&n,&k);
int t=1;
long num=0;
int r=0;
int e=0;
while(1){
long max=(count(t)-count(t-1))*t;
if(num+max>=k){
k-=num;
r=k/t;
e=k%t;
n-=r;
break;
}
num+=max;
n-=count(t)-count(t-1);
t++;
}
r+=count(t-1)-1;
if(n<0 || n==0 && e!=0) printf("-1");
else if(e==0){
char m[10];
sprintf(m,"%d",r);
printf("%c",m[strlen(m)-1]);
}
else{
r+=1;
char m[10];
sprintf(m,"%d",r);
printf("%c",m[e-1]);
}
}