





"""simple docstring"""


__magic_name__					:				List[Any]	= {
    """0""": 1,
    """1""": 1,
    """2""": 2,
    """3""": 6,
    """4""": 2_4,
    """5""": 1_2_0,
    """6""": 7_2_0,
    """7""": 5_0_4_0,
    """8""": 4_0_3_2_0,
    """9""": 3_6_2_8_8_0,
}

__magic_name__					:				Optional[int]	= {1_4_5: 1_4_5}

__magic_name__					:				int	= {
    1_4_5: 0,
    1_6_9: 3,
    3_6_3_0_1: 3,
    1_4_5_4: 3,
    8_7_1: 2,
    4_5_3_6_1: 2,
    8_7_2: 2,
}

def     UpperCamelCase       (SCREAMING_SNAKE_CASE    ):
						if n in CACHE_SUM_DIGIT_FACTORIALS:
												return CACHE_SUM_DIGIT_FACTORIALS[n]
						UpperCamelCase							:		Any							      = sum(DIGIT_FACTORIALS[let] for let in str(SCREAMING_SNAKE_CASE    )    )
						UpperCamelCase							:		Any							      = ret
						return ret

def     UpperCamelCase       (SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE = None    ):
						UpperCamelCase							:		Optional[Any]							      = previous or set()
						if n in CHAIN_LENGTH_CACHE:
												return CHAIN_LENGTH_CACHE[n]
						UpperCamelCase							:		Optional[int]							      = sum_digit_factorials(SCREAMING_SNAKE_CASE    )
						if next_number in previous:
												UpperCamelCase							:		Optional[int]							      = 0
												return 0
						else:
												previous.add(SCREAMING_SNAKE_CASE    )
												UpperCamelCase							:		List[str]							      = 1 + chain_length(SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE    )
												UpperCamelCase							:		str							      = ret
												return ret

def     UpperCamelCase       (SCREAMING_SNAKE_CASE = 60       ,    SCREAMING_SNAKE_CASE = 100_0000    ):
						return sum(1 for i in range(1       ,    SCREAMING_SNAKE_CASE    ) if chain_length(SCREAMING_SNAKE_CASE    ) == num_terms    )


if __name__ == "__main__":
		print(f'''{solution() = }''')










"""simple docstring"""


from __future__ import annotations

def     UpperCamelCase       (SCREAMING_SNAKE_CASE    ):
						UpperCamelCase							:		Tuple							      = [0] * max_one

						for i in range(0       ,    SCREAMING_SNAKE_CASE    ):
												UpperCamelCase							:		Union[str, Any]							      = i

						for i in range(2       ,    SCREAMING_SNAKE_CASE    ):
												if totients[i] == i:
																		for j in range(SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE    ):
																								totients[j] -= totients[j] // i

						return totients

def     UpperCamelCase       (SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE    ):
						return sorted(str(SCREAMING_SNAKE_CASE    )    ) == sorted(str(SCREAMING_SNAKE_CASE    )    )

def     UpperCamelCase       (SCREAMING_SNAKE_CASE = 1000_0000    ):
						UpperCamelCase							:		List[str]							      = 1  # i
						UpperCamelCase							:		Optional[int]							      = 0  # φ(i)
						UpperCamelCase							:		List[str]							      = get_totients(max_n + 1    )

						for i in range(2       ,    max_n + 1    ):
												UpperCamelCase							:		Tuple							      = totients[i]

												if i * min_denominator < min_numerator * t and has_same_digits(SCREAMING_SNAKE_CASE       ,    SCREAMING_SNAKE_CASE    ):
																		UpperCamelCase							:		str							      = i
																		UpperCamelCase							:		Tuple							      = t

						return min_numerator


if __name__ == "__main__":
		print(f'''{solution() = }''')



