int main() { int n,t,k=0,l=0,ent,ext,temp; scanf("%d %d",&n,&t); if( n>=2 && n<=100000 && t>=1 && t<=1000) { int a[n]; while(k<n){ scanf("%d",&temp); if(temp>=1 && temp<=3){ a[k] = temp; k++; } } while(t){ scanf("%d %d",&ent,&ext); if(ent < ext && ent>=0 && ext < n && (ext-ent+1)>=2 && (ext-ent+1)<=minnum(n,1000)){ printf("%d\n",min(a,ent,ext)); t--; } } } return 0; }
int main(){ ans[0]=1; ans[1]=2; ans[2]=3; ans[3]=4; ans[4]=5; ans[5]=6; ans[6]=7; p[2]=3; p[3]=2; p[5]=1; p[7]=1; n=6; while(n<5841){ while(ans[p[2]]*2==ans[n]) p[2]++; while(ans[p[3]]*3==ans[n]) p[3]++; while(ans[p[5]]*5==ans[n]) p[5]++; while(ans[p[7]]*7==ans[n]) p[7]++; k=minnum(); n++; ans[n]=ans[p[k]]*k; p[k]++; } while((scanf("%d",&n)!=EOF)&&(n)){ if((n%100>10)&&(n%100<20)){ printf("The %dth humble number is %lld.\n",n,ans[n-1]); continue; } if(n%10==1) printf("The %dst humble number is %lld.\n",n,ans[n-1]); if(n%10==2) printf("The %dnd humble number is %lld.\n",n,ans[n-1]); if(n%10==3) printf("The %drd humble number is %lld.\n",n,ans[n-1]); if((n%10>3)||(!(n%10))) printf("The %dth humble number is %lld.\n",n,ans[n-1]); } return 0; }