|
|
@ -8,10 +8,10 @@ package class_2022_11_5_week;
|
|
|
|
public class Code04_NthDigit {
|
|
|
|
public class Code04_NthDigit {
|
|
|
|
|
|
|
|
|
|
|
|
public static final long[] under = {
|
|
|
|
public static final long[] under = {
|
|
|
|
0L,// 0位数,一共能解决几个位
|
|
|
|
0L, // 0位数,一共能解决几个位
|
|
|
|
9L,// 1位数,一共能解决几个位
|
|
|
|
9L, // 1位数,一共能解决几个位
|
|
|
|
189L,// 1~2位数,一共能解决几个位
|
|
|
|
189L, // 1~2位数,一共能解决几个位
|
|
|
|
2889L,// 1~3位数,一共能解决几个位
|
|
|
|
2889L, // 1~3位数,一共能解决几个位
|
|
|
|
38889L,
|
|
|
|
38889L,
|
|
|
|
488889L,
|
|
|
|
488889L,
|
|
|
|
5888889L,
|
|
|
|
5888889L,
|
|
|
@ -23,8 +23,8 @@ public class Code04_NthDigit {
|
|
|
|
public static final int[] help = {
|
|
|
|
public static final int[] help = {
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
1, // 1
|
|
|
|
1, // 1
|
|
|
|
10,// 2
|
|
|
|
10, // 2
|
|
|
|
100,// 3
|
|
|
|
100, // 3
|
|
|
|
1000, // 4
|
|
|
|
1000, // 4
|
|
|
|
10000,
|
|
|
|
10000,
|
|
|
|
100000,
|
|
|
|
100000,
|
|
|
@ -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);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|