Tricky Sequence Question

yes, because, i have appended upto 500 only, so that we can not get the index of the next integer., and i am giving output as “index out of bound” in such situations

@rajasekharcool and @sumanth_puri can you please specify why you down voted my answer, is there problem in description or is it only because I down voted your slow solutions?

I’m just saying if @toiletpaper do not specify otherwise for me limit like 1500 is not good enough…

On my PC code for input 100.000 (10^5) and 480.000 (48*10^4) returns answer in 15 seconds.

because…, i am unable to estimate the running time with ur description., so if u provide ur code., we can try to do…

#include
#include
using namespace std;
int fun(int a){
if(a<=9)return a;
int i,s=0;
for(i=0;;i++){
s+=(i==0)?1:((pow(10,i)-pow(10,i-1))*i);
if(a<=s)
break;
}
int k=a-s+((pow(10,i)-pow(10,i-1))*i);
int no=floor((float)k/i);
int val=pow(10,i-1)-pow(10,i-2);
for(;no>0;no–)
val++;
int c=k%i;

for(;c>=0;c--){
k=val%10;
val=val/10;
}
return k;
}

main(){int a;
cout<<"enter index:"<<endl;
cin>>a;
cout<<"digit is:"<<fun(a)<<endl;

}

This one is not working, maybe you can describe your approach, but expected result for inputs 1393, 1394 and 1395 is 5, 0 and 1, your code returns 1, 4, 9 - http://ideone.com/coIv3I

I added the link to my algorithm :wink:

I added the link to my algorithm :wink: It runs for 10^18 in less than 0.1s

I added link to the algorithm, it can find the result for 10^18 in less than 0.1s :wink:

index = [0,10^18]

@betlista : excellent answer

1 Like

@betlista: extra ordinary

//