




"""simple docstring"""







from math import pow





def      __snake_case (				_lowercase			,_lowercase			,_lowercase			,_lowercase			,_lowercase			,):


    """simple docstring"""







    if current_sum == needed_sum:
        # If the sum of the powers is equal to needed_sum, then we have a solution.
        solutions_count += 1
        return current_sum, solutions_count

    UpperCamelCase              =	int(pow(_lowercase			,_lowercase    )    )
    if current_sum + i_to_n <= needed_sum:
        # If the sum of the powers is less than needed_sum, then continue adding powers.
        current_sum += i_to_n
        UpperCamelCase       ,	UpperCamelCase              =	backtrack(
            _lowercase			,_lowercase			,current_number + 1			,_lowercase			,_lowercase    )
        current_sum -= i_to_n
    if i_to_n < needed_sum:
        # If the power of i is less than needed_sum, then try with the next power.
        UpperCamelCase       ,	UpperCamelCase              =	backtrack(
            _lowercase			,_lowercase			,current_number + 1			,_lowercase			,_lowercase    )
    return current_sum, solutions_count





def      __snake_case (				_lowercase			,_lowercase    ):


    """simple docstring"""







    if not (1 <= needed_sum <= 1000 and 2 <= power <= 10):
        raise ValueError(
            '''Invalid input\n'''
            '''needed_sum must be between 1 and 1000, power between 2 and 10.'''    )

    return backtrack(_lowercase			,_lowercase			,1			,0			,0    )[1]  # Return the solutions_count


if __name__ == "__main__":
  import doctest

  doctest.testmod()



import unittest

from transformers import BigBirdConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
				import jax

				from transformers.models.big_bird.modeling_flax_big_bird import (
				    FlaxBigBirdForCausalLM,
				    FlaxBigBirdForMaskedLM,
				    FlaxBigBirdForMultipleChoice,
				    FlaxBigBirdForPreTraining,
				    FlaxBigBirdForQuestionAnswering,
				    FlaxBigBirdForSequenceClassification,
				    FlaxBigBirdForTokenClassification,
				    FlaxBigBirdModel,
				)






class    _UpperCamelCase     (       unittest.TestCase					):

				"""simple docstring"""







				def __init__(    self					, a__					, a__=2					, a__=56					, a__=True					, a__=True					, a__=True					, a__=True					, a__=99					, a__=32					, a__=2					, a__=2					, a__=7					, a__="gelu_new"					, a__=0.1					, a__=0.1					, a__=512					, a__=16					, a__=2					, a__=0.02					, a__=4					, a__="block_sparse"					, a__=True					, a__=False					, a__=2					, a__=3					, )						->					List[Any]:
					A             =					parent
					A             =					batch_size
					A             =					seq_length
					A             =					is_training
					A             =					use_attention_mask
					A             =					use_token_type_ids
					A             =					use_labels
					A             =					vocab_size
					A             =					hidden_size
					A             =					num_hidden_layers
					A             =					num_attention_heads
					A             =					intermediate_size
					A             =					hidden_act
					A             =					hidden_dropout_prob
					A             =					attention_probs_dropout_prob
					A             =					max_position_embeddings
					A             =					type_vocab_size
					A             =					type_sequence_label_size
					A             =					initializer_range
					A             =					num_choices

					A             =					rescale_embeddings
					A             =					attention_type
					A             =					use_bias
					A             =					block_size
					A             =					num_random_blocks

				def   _UpperCAmelCase       (    self )						->					List[Any]:
					A             =					ids_tensor([self.batch_size, self.seq_length]					, self.vocab_size )

					A             =					None
					if self.use_attention_mask:
						A             =					random_attention_mask([self.batch_size, self.seq_length] )

					A             =					None
					if self.use_token_type_ids:
						A             =					ids_tensor([self.batch_size, self.seq_length]					, self.type_vocab_size )

					A             =					BigBirdConfig(
					    vocab_size=self.vocab_size					, hidden_size=self.hidden_size					, num_hidden_layers=self.num_hidden_layers					, num_attention_heads=self.num_attention_heads					, intermediate_size=self.intermediate_size					, hidden_act=self.hidden_act					, hidden_dropout_prob=self.hidden_dropout_prob					, attention_probs_dropout_prob=self.attention_probs_dropout_prob					, max_position_embeddings=self.max_position_embeddings					, type_vocab_size=self.type_vocab_size					, is_decoder=a__					, initializer_range=self.initializer_range					, attention_type=self.attention_type					, block_size=self.block_size					, num_random_blocks=self.num_random_blocks					, use_bias=self.use_bias					, rescale_embeddings=self.rescale_embeddings					, )

					return config, input_ids, token_type_ids, attention_mask

				def   _UpperCAmelCase       (    self )						->					Optional[int]:
					A             =					self.prepare_config_and_inputs()
					A       ,      A       ,      A       ,      A             =					config_and_inputs
					A             =					{
					    """input_ids""": input_ids,
					    """token_type_ids""": token_type_ids,
					    """attention_mask""": attention_mask,
					}
					return config, inputs_dict






@require_flax
class    _UpperCamelCase     (       __snake_case     ,		unittest.TestCase					):

				"""simple docstring"""







				lowerCAmelCase					=			(
				    (
				        FlaxBigBirdForCausalLM,
				        FlaxBigBirdModel,
				        FlaxBigBirdForPreTraining,
				        FlaxBigBirdForMaskedLM,
				        FlaxBigBirdForMultipleChoice,
				        FlaxBigBirdForQuestionAnswering,
				        FlaxBigBirdForSequenceClassification,
				        FlaxBigBirdForTokenClassification,
				    )
				    if is_flax_available()
				    else ()
				)

				lowerCAmelCase					=			False
				lowerCAmelCase					=			False

				def   _UpperCAmelCase       (    self )						->					Optional[int]:
					A             =					FlaxBigBirdModelTester(self )

				@slow
				# copied from `test_modeling_flax_common` because it takes much longer than other models
				def   _UpperCAmelCase       (    self )						->					Tuple:
					super().test_from_pretrained_save_pretrained()

				@slow
				# copied from `test_modeling_flax_common` because it takes much longer than other models
				def   _UpperCAmelCase       (    self )						->					Dict:
					super().test_from_pretrained_with_no_automatic_init()

				@slow
				# copied from `test_modeling_flax_common` because it takes much longer than other models
				def   _UpperCAmelCase       (    self )						->					str:
					super().test_no_automatic_init()

				@slow
				# copied from `test_modeling_flax_common` because it takes much longer than other models
				def   _UpperCAmelCase       (    self )						->					List[Any]:
					super().test_hidden_states_output()

				@slow
				def   _UpperCAmelCase       (    self )						->					str:
					for model_class_name in self.all_model_classes:
						A             =					model_class_name.from_pretrained("""google/bigbird-roberta-base""" )
						self.assertIsNotNone(a__ )

				def   _UpperCAmelCase       (    self )						->					Optional[int]:
					if self.test_attn_probs:
						super().test_attention_outputs()

				@slow
				# copied from `test_modeling_flax_common` because it takes much longer than other models
				def   _UpperCAmelCase       (    self )						->					List[Any]:
					A       ,      A             =					self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
						with self.subTest(model_class.__name__ ):
							A             =					self._prepare_for_class(a__					, a__ )
							A             =					model_class(a__ )

							@jax.jit
							def model_jitted(a__					, a__=None					, **a__ ):
								return model(input_ids=a__					, attention_mask=a__					, **a__ )

							with self.subTest("""JIT Enabled""" ):
								A             =					model_jitted(**a__ ).to_tuple()

							with self.subTest("""JIT Disabled""" ):
								with jax.disable_jit():
									A             =					model_jitted(**a__ ).to_tuple()

							self.assertEqual(len(a__ )					, len(a__ ) )
							for jitted_output, output in zip(a__					, a__ ):
								self.assertEqual(jitted_output.shape					, output.shape )

				def   _UpperCAmelCase       (    self					, a__					, a__					, a__					, a__=1e-5					, a__="outputs"					, a__=None )						->					Tuple:
					# `bigbird_block_sparse_attention` in `FlaxBigBird` returns `attention_probs = None`, while in PyTorch version,
					# an effort was done to return `attention_probs` (yet to be verified).
					if name.startswith("""outputs.attentions""" ):
						return
					else:
						super().check_pt_flax_outputs(a__					, a__					, a__					, a__					, a__					, a__ )



