'''simple docstring'''




__snake_case   :      Any						    =  {
    '0': 1,
    '1': 1,
    '2': 2,
    '3': 6,
    '4': 24,
    '5': 120,
    '6': 720,
    '7': 5_040,
    '8': 40_320,
    '9': 362_880,
}

__snake_case   :      List[Any]						    =  {145: 145}

__snake_case   :      Tuple						    =  {
    145: 0,
    169: 3,
    36_301: 3,
    1_454: 3,
    871: 2,
    45_361: 2,
    872: 2,
}





def      _UpperCAmelCase    (							_UpperCamelCase    :	int   )	->      int:
    if n in CACHE_SUM_DIGIT_FACTORIALS:
        return CACHE_SUM_DIGIT_FACTORIALS[n]
    A_     =   sum(DIGIT_FACTORIALS[let] for let in str(_UpperCamelCase   )   )
    A_     =   ret
    return ret





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





def      _UpperCAmelCase    (							_UpperCamelCase    :	int = 60,   _UpperCamelCase    :	int = 1_00_00_00   )	->      int:
    return sum(1 for i in range(1,   _UpperCamelCase   ) if chain_length(_UpperCamelCase   ) == num_terms   )


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







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


UpperCAmelCase							= {'''configuration_nat''': ['''NAT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''NatConfig''']}


try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCAmelCase							= [
     '''NAT_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''NatForImageClassification''',
     '''NatModel''',
     '''NatPreTrainedModel''',
     '''NatBackbone''',
 ]

if TYPE_CHECKING:
 from .configuration_nat import NAT_PRETRAINED_CONFIG_ARCHIVE_MAP, NatConfig

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_nat import (
      NAT_PRETRAINED_MODEL_ARCHIVE_LIST,
      NatBackbone,
      NatForImageClassification,
      NatModel,
      NatPreTrainedModel,
  )

else:
 import sys

 UpperCAmelCase							= _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)



