|
|
@ -57,35 +57,15 @@ public class Code04_NthDigit {
|
|
|
|
// nth : 第几个
|
|
|
|
// nth : 第几个
|
|
|
|
public static int number(int path, int len, int offset, int all, int nth) {
|
|
|
|
public static int number(int path, int len, int offset, int all, int nth) {
|
|
|
|
if (offset == 0) {
|
|
|
|
if (offset == 0) {
|
|
|
|
// 5 3 2 1 6
|
|
|
|
|
|
|
|
// path : 6 1 2 3 5
|
|
|
|
|
|
|
|
// 5 4 3 2 1(高)
|
|
|
|
|
|
|
|
return (path / help[nth]) % 10;
|
|
|
|
return (path / help[nth]) % 10;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// 3 _ _ _ _
|
|
|
|
int cur = offset == all ? 1 : 0;
|
|
|
|
int cur = 0;
|
|
|
|
int j = nth / (len * offset);
|
|
|
|
int minus = 0;
|
|
|
|
if (nth % (len * offset) == 0) {
|
|
|
|
// i是开始尝试的数字! 最高位 i 1 2 3 4...
|
|
|
|
j--;
|
|
|
|
// 不是最高位 0 1 2 3 4
|
|
|
|
|
|
|
|
// 股数j = 1 2 3 4
|
|
|
|
|
|
|
|
for (int i = offset == all ? 1 : 0, j = 1; i <= 9; i++, j++) {
|
|
|
|
|
|
|
|
// 搞定了多少
|
|
|
|
|
|
|
|
long under = (long) j * len * offset;
|
|
|
|
|
|
|
|
if (under >= nth) {
|
|
|
|
|
|
|
|
cur = i;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// < i不要
|
|
|
|
|
|
|
|
minus = (int) under;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 1458 - 1200
|
|
|
|
cur += j;
|
|
|
|
// cur !
|
|
|
|
return number(cur * (all / offset) + path, len, offset / 10, all, nth - j * len * offset);
|
|
|
|
// n - minus
|
|
|
|
|
|
|
|
// 10000
|
|
|
|
|
|
|
|
// !1000
|
|
|
|
|
|
|
|
// !!100
|
|
|
|
|
|
|
|
// !!!10
|
|
|
|
|
|
|
|
return number(cur * (all / offset) + path, len, offset / 10, all, nth - minus);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|