


"""simple docstring"""
__SCREAMING_SNAKE_CASE				:     Tuple		=     {
    '0': 1,
    '1': 1,
    '2': 2,
    '3': 6,
    '4': 24,
    '5': 120,
    '6': 720,
    '7': 5_040,
    '8': 40_320,
    '9': 362_880,
}

__SCREAMING_SNAKE_CASE				:     Any		=     {145: 145}

__SCREAMING_SNAKE_CASE				:     List[Any]		=     {
    145: 0,
    169: 3,
    36_301: 3,
    1_454: 3,
    871: 2,
    45_361: 2,
    872: 2,
}







def     _a					(   _SCREAMING_SNAKE_CASE					)     ->					int:
							if n in CACHE_SUM_DIGIT_FACTORIALS:
														return CACHE_SUM_DIGIT_FACTORIALS[n]
							snake_case_     							=		sum(DIGIT_FACTORIALS[let] for let in str(_SCREAMING_SNAKE_CASE					)					)
							snake_case_     							=		ret
							return ret







def     _a					(   _SCREAMING_SNAKE_CASE					,			_SCREAMING_SNAKE_CASE = None					)     ->					int:
							snake_case_     							=		previous or set()
							if n in CHAIN_LENGTH_CACHE:
														return CHAIN_LENGTH_CACHE[n]
							snake_case_     							=		sum_digit_factorials(_SCREAMING_SNAKE_CASE					)
							if next_number in previous:
														snake_case_     							=		0
														return 0
							else:
														previous.add(_SCREAMING_SNAKE_CASE					)
														snake_case_     							=		1 + chain_length(_SCREAMING_SNAKE_CASE					,			_SCREAMING_SNAKE_CASE					)
														snake_case_     							=		ret
														return ret







def     _a					(   _SCREAMING_SNAKE_CASE = 60					,			_SCREAMING_SNAKE_CASE = 1_000_000					)     ->					int:
							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"""
import doctest

import projectq
from projectq.ops import H, Measure







def     _a					(   _SCREAMING_SNAKE_CASE					)     ->					int:
							snake_case_     							=		quantum_engine.allocate_qubit()
							H | qubit
							Measure | qubit
							return int(_SCREAMING_SNAKE_CASE					)


if __name__ == "__main__":
				doctest.testmod()

				# initialises a new quantum backend
				__SCREAMING_SNAKE_CASE				:     Dict		=     projectq.MainEngine()

				# Generate a list of 10 random numbers
				__SCREAMING_SNAKE_CASE				:     Optional[Any]		=     [get_random_number(quantum_engine) for _ in range(10)]

				# Flushes the quantum engine from memory
				quantum_engine.flush()

				print('Random numbers', random_numbers_list)



