


'''simple docstring'''

from math import factorial

lowerCAmelCase				:dict[str, int]        =      {str(digit): factorial(digit) for digit in range(1_0)}





def lowerCamelCase      (      lowerCAmelCase    :     int		):





	"""simple docstring"""







	if not isinstance(lowerCAmelCase		,		lowerCAmelCase		):
		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(lowerCAmelCase		)		)





def lowerCamelCase      (      lowerCAmelCase    :     int = 60		,		lowerCAmelCase    :     int = 100_0000		):





	"""simple docstring"""







	if not isinstance(lowerCAmelCase		,		lowerCAmelCase		) or not isinstance(lowerCAmelCase		,		lowerCAmelCase		):
		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
	__magic_name__	:   Tuple					     =					0
	# the cached sizes of the previous chains
	__magic_name__	:   dict[int, int]					     =					{}

	for start_chain_element in range(1		,		lowerCAmelCase		):
		# The temporary set will contain the elements of the chain
		__magic_name__	:   List[Any]					     =					set()
		__magic_name__	:   Any					     =					0

		# Stop computing the chain when you find a cached size, a repeating item or the
		# length is greater then the desired one.
		__magic_name__	:   Tuple					     =					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(lowerCAmelCase		)
			chain_set_length += 1
			__magic_name__	:   List[Any]					     =					digit_factorial_sum(lowerCAmelCase		)

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

		__magic_name__	:   str					     =					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()}')



'''simple docstring'''

import unittest

import numpy as np
import torch

from diffusers import KarrasVePipeline, KarrasVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()
class _lowerCamelCase	(						unittest.TestCase							):



		'''simple docstring'''







		@property
		def        __lowerCAmelCase		( self		:						Dict      )  ->			List[str]:
			torch.manual_seed(0      )
			__magic_name__	:   Dict					     =					UNetaDModel(
			    block_out_channels=(32, 64)  ,					layers_per_block=2  ,					sample_size=32  ,					in_channels=3  ,					out_channels=3  ,					down_block_types=('DownBlock2D', 'AttnDownBlock2D')  ,					up_block_types=('AttnUpBlock2D', 'UpBlock2D')  ,					)
			return model







		def        __lowerCAmelCase		( self		:						str      )  ->			Any:
			__magic_name__	:   Union[str, Any]					     =					self.dummy_uncond_unet
			__magic_name__	:   str					     =					KarrasVeScheduler()

			__magic_name__	:   List[Any]					     =					KarrasVePipeline(unet=_A  ,					scheduler=_A      )
			pipe.to(_A      )
			pipe.set_progress_bar_config(disable=_A      )

			__magic_name__	:   Dict					     =					torch.manual_seed(0      )
			__magic_name__	:   int					     =					pipe(num_inference_steps=2  ,					generator=_A  ,					output_type='numpy'      ).images

			__magic_name__	:   Any					     =					torch.manual_seed(0      )
			__magic_name__	:   str					     =					pipe(num_inference_steps=2  ,					generator=_A  ,					output_type='numpy'  ,					return_dict=_A      )[0]

			__magic_name__	:   int					     =					image[0, -3:, -3:, -1]
			__magic_name__	:   str					     =					image_from_tuple[0, -3:, -3:, -1]

			assert image.shape == (1, 32, 32, 3)
			__magic_name__	:   List[Any]					     =					np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]      )

			assert np.abs(image_slice.flatten() - expected_slice      ).max() < 1E-2
			assert np.abs(image_from_tuple_slice.flatten() - expected_slice      ).max() < 1E-2







@slow
@require_torch
class _lowerCamelCase	(						unittest.TestCase							):



		'''simple docstring'''







		def        __lowerCAmelCase		( self		:						List[Any]      )  ->			str:
			__magic_name__	:   Optional[int]					     =					'google/ncsnpp-celebahq-256'
			__magic_name__	:   List[str]					     =					UNetaDModel.from_pretrained(_A      )
			__magic_name__	:   int					     =					KarrasVeScheduler()

			__magic_name__	:   str					     =					KarrasVePipeline(unet=_A  ,					scheduler=_A      )
			pipe.to(_A      )
			pipe.set_progress_bar_config(disable=_A      )

			__magic_name__	:   Any					     =					torch.manual_seed(0      )
			__magic_name__	:   Union[str, Any]					     =					pipe(num_inference_steps=20  ,					generator=_A  ,					output_type='numpy'      ).images

			__magic_name__	:   List[str]					     =					image[0, -3:, -3:, -1]
			assert image.shape == (1, 256, 256, 3)
			__magic_name__	:   int					     =					np.array([0.578, 0.5811, 0.5924, 0.5809, 0.587, 0.5886, 0.5861, 0.5802, 0.586]      )

			assert np.abs(image_slice.flatten() - expected_slice      ).max() < 1E-2