题解 | 无限长正整数排列字符串
无限长正整数排列字符串
https://www.nowcoder.com/practice/82c92d2321bb4220a3006d52a95a8bdd
n = int(input())
length = 1 # 当前数字的位数
count = 9 # 当前位数的数字的总个数(1位数有9个,2位数有90个,等等)
start = 1 # 当前位数的起始数字(1位数从1开始,2位数从10开始,等等)
while n > length * count:
n -= length * count
length += 1
count *= 10
start *= 10
# 找到具体的数字
num = start + (n - 1) // length
# 找到在该数字中的具体位置
pos_in_num = (n - 1) % length
print(str(num)[pos_in_num])
查看16道真题和解析