【HDOJ】1597 find the nth digit
二分。
1 #include <stdio.h> 2 #include <math.h> 3 4 int main() { 5 int case_n; 6 double n, tmp, l, r; 7 int m; 8 9 scanf("%d", &case_n); 10 11 while (case_n--) { 12 scanf("%lf", &n); 13 tmp = sqrt(n+n); 14 tmp = ceil(tmp); 15 l = (tmp*tmp-tmp)/2; 16 r = (tmp*tmp+tmp)/2; 17 while ( !(l<n && r>=n) ) { 18 --tmp; 19 l = (tmp*tmp-tmp)/2; 20 r = (tmp*tmp+tmp)/2; 21 } 22 m = (int)(n-l); 23 m %= 9; 24 if (m==0) m=9; 25 printf("%d\n", m); 26 } 27 28 return 0; 29 }