
from math import factorial

A_		:     Optional[Any]        =     {str(digit): factorial(digit) for digit in range(10)}


def 	UpperCAmelCase__      (      UpperCAmelCase__ :int					):






 '''simple docstring'''

 if not isinstance(UpperCAmelCase__ ,					UpperCAmelCase__					):
  raise TypeError("Parameter number must be int"					)

 if number < 0:
  raise ValueError("Parameter number must be greater than or equal to 0"					)

 # Converts number in string to iterate on its digits and adds its factorial.
 return sum(DIGIT_FACTORIAL[digit] for digit in str(UpperCAmelCase__					)					)


def 	UpperCAmelCase__      (      UpperCAmelCase__ :int = 60 ,					UpperCAmelCase__ :int = 1_00_00_00					):






 '''simple docstring'''

 if not isinstance(UpperCAmelCase__ ,					UpperCAmelCase__					) or not isinstance(UpperCAmelCase__ ,					UpperCAmelCase__					):
  raise TypeError("Parameters chain_length and number_limit must be int"					)

 if chain_length <= 0 or number_limit <= 0:
  raise ValueError(
      "Parameters chain_length and number_limit must be greater than 0"					)

 # the counter for the chains with the exact desired length
 a						=		0
 # the cached sizes of the previous chains
 a						=		{}

 for start_chain_element in range(1 ,					UpperCAmelCase__					):
  # The temporary set will contain the elements of the chain
  a						=		set()
  a						=		0

  # Stop computing the chain when you find a cached size, a repeating item or the
  # length is greater then the desired one.
  a						=		start_chain_element
  while (
      chain_element not in chain_sets_lengths
      and chain_element not in chain_set
      and chain_set_length <= chain_length
  ):
   chain_set.add(UpperCAmelCase__					)
   chain_set_length += 1
   a						=		digit_factorial_sum(UpperCAmelCase__					)

  if chain_element in chain_sets_lengths:
   chain_set_length += chain_sets_lengths[chain_element]

  a						=		chain_set_length

  # If chain contains the exact amount of elements increase the counter
  if chain_set_length == chain_length:
   chains_counter += 1

 return chains_counter


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     print(F"""{solution()}""")






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A_		:     Optional[int]        =     {
    '''configuration_instructblip''': [
        '''INSTRUCTBLIP_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''InstructBlipConfig''',
        '''InstructBlipQFormerConfig''',
        '''InstructBlipVisionConfig''',
    ],
    '''processing_instructblip''': ['''InstructBlipProcessor'''],
}

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     A_		:     List[Any]        =     [
         '''INSTRUCTBLIP_PRETRAINED_MODEL_ARCHIVE_LIST''',
         '''InstructBlipQFormerModel''',
         '''InstructBlipPreTrainedModel''',
         '''InstructBlipForConditionalGeneration''',
         '''InstructBlipVisionModel''',
     ]

if TYPE_CHECKING:
     from .configuration_instructblip import (
         INSTRUCTBLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
         InstructBlipConfig,
         InstructBlipQFormerConfig,
         InstructBlipVisionConfig,
     )
     from .processing_instructblip import InstructBlipProcessor

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_instructblip import (
              INSTRUCTBLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
              InstructBlipForConditionalGeneration,
              InstructBlipPreTrainedModel,
              InstructBlipQFormerModel,
              InstructBlipVisionModel,
          )

else:
     import sys

     A_		:     Tuple        =     _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)

