def get_digit(n): n -= 1 i = 0 while True: count_digit = (i + 1) * 9 * (10 ** i) if n < count_digit: break n -= count_digit i += 1 num, index = divmod(n, i + 1) return int(str(num + 10 ** i)[index]) def multi_digit(limit): multi = 1 n = 1 while n < limit + 1: multi *= get_digit(n) n *= 10 return multi print(multi_digit(1000000))