Thinking: each time the position pos mapped to the corresponding symmetrical sections. Until the [1,5] interval
Which should be noted is the need to find a distribution of $. Separate treatment
package com.company.dp; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class recursive query substring { public static void main (String [] args) { Scanner scanner=new Scanner(System.in); int case_num=Integer.parseInt(scanner.nextLine()); for (int i = 0; i < case_num; i++) { long pos=Long.parseLong(scanner.nextLine()); char res=getNum(pos); System.out.println(res); } scanner.close(); } private static char getNum(long pos) { long[] s=new long[50]; s[0]=5; for (int i = 1; i < s.length; i++) { s[i]=s[i-1]*2+i; } for (int i = 0; i < s.length; i++) { System.out.println(s[i]); } String str0="12345"; while(pos>5){ for (int i = 1; i < s.length; i++) { if(pos>=s[i-1]&&pos<=s[i]){ if(2*pos-s[i]>=0&&2*pos-s[i]<=i)return '$'; pos=s[i]-pos+1; break; } } } return str0.charAt(((int) pos)-1); } }