






"""simple docstring"""
import numpy as np

def 							snake_case (  A__      ,A__      ,A__ = 1e-12      ,A__ = 1_00      ,):
			assert np.shape(__snake_case		)[0] == np.shape(__snake_case		)[1]
			# Ensure proper dimensionality.
			assert np.shape(__snake_case		)[0] == np.shape(__snake_case		)[0]
			# Ensure inputs are either both complex or both real
			assert np.iscomplexobj(__snake_case		) == np.iscomplexobj(__snake_case		)
			UpperCAmelCase_	:					Optional[Any]     	=   np.iscomplexobj(__snake_case		)
			if is_complex:
						# Ensure complex input_matrix is Hermitian
						assert np.array_equal(__snake_case      ,input_matrix.conj().T		)

			# Set convergence to False. Will define convergence when we exceed max_iterations
			# or when we have small changes from one iteration to next.

			UpperCAmelCase_	:					Union[str, Any]     	=   False
			UpperCAmelCase_	:					Optional[Any]     	=   0
			UpperCAmelCase_	:					Union[str, Any]     	=   0
			UpperCAmelCase_	:					Optional[Any]     	=   1e12

			while not convergence:
						# Multiple matrix by the vector.
						UpperCAmelCase_	:					Dict     	=   np.dot(__snake_case      ,__snake_case		)
						# Normalize the resulting output vector.
						UpperCAmelCase_	:					Any     	=   w / np.linalg.norm(__snake_case		)
						# Find rayleigh quotient
						# (faster than usual b/c we know vector is normalized already)
						UpperCAmelCase_	:					Dict     	=   vector.conj().T if is_complex else vector.T
						UpperCAmelCase_	:					Optional[Any]     	=   np.dot(__snake_case      ,np.dot(__snake_case      ,__snake_case		)		)

						# Check convergence.
						UpperCAmelCase_	:					Union[str, Any]     	=   np.abs(lambda_ - lambda_previous		) / lambda_
						iterations += 1

						if error <= error_tol or iterations >= max_iterations:
									UpperCAmelCase_	:					Union[str, Any]     	=   True

						UpperCAmelCase_	:					Union[str, Any]     	=   lambda_

			if is_complex:
						UpperCAmelCase_	:					Any     	=   np.real(lambda_		)

			return lambda_, vector

def 							snake_case (  ):
			UpperCAmelCase_	:					str     	=   np.array([[41, 4, 20], [4, 26, 30], [20, 30, 50]]		)
			UpperCAmelCase_	:					Optional[int]     	=   np.array([41, 4, 20]		)
			UpperCAmelCase_	:					List[Any]     	=   real_input_matrix.astype(np.complexaaa		)
			UpperCAmelCase_	:					Optional[int]     	=   np.triu(1j * complex_input_matrix      ,1		)
			complex_input_matrix += imag_matrix
			complex_input_matrix += -1 * imag_matrix.T
			UpperCAmelCase_	:					Optional[Any]     	=   np.array([41, 4, 20]		).astype(np.complexaaa		)

			for problem_type in ["real", "complex"]:
						if problem_type == "real":
									UpperCAmelCase_	:					Union[str, Any]     	=   real_input_matrix
									UpperCAmelCase_	:					Any     	=   real_vector
						elif problem_type == "complex":
									UpperCAmelCase_	:					Optional[int]     	=   complex_input_matrix
									UpperCAmelCase_	:					Union[str, Any]     	=   complex_vector

						# Our implementation.
						UpperCAmelCase_	,      UpperCAmelCase_	:					Union[str, Any]     	=   power_iteration(__snake_case      ,__snake_case		)

						# Numpy implementation.

						# Get eigenvalues and eigenvectors using built-in numpy
						# eigh (eigh used for symmetric or hermetian matrices).
						UpperCAmelCase_	,      UpperCAmelCase_	:					Optional[Any]     	=   np.linalg.eigh(__snake_case		)
						# Last eigenvalue is the maximum one.
						UpperCAmelCase_	:					int     	=   eigen_values[-1]
						# Last column in this matrix is eigenvector corresponding to largest eigenvalue.
						UpperCAmelCase_	:					Optional[int]     	=   eigen_vectors[:, -1]

						# Check our implementation and numpy gives close answers.
						assert np.abs(eigen_value - eigen_value_max		) <= 1e-6
						# Take absolute values element wise of each eigenvector.
						# as they are only unique to a minus sign.
						assert np.linalg.norm(np.abs(__snake_case		) - np.abs(__snake_case		)		) <= 1e-6


if __name__ == "__main__":
			import doctest

			doctest.testmod()
			test_power_iteration()











"""simple docstring"""
def 							A						(				__snake_case: int  )    ->		int:

       """simple docstring"""





       if divisor % 5 == 0 or divisor % 2 == 0:
              return 0
       __magic_name__      				=    1
       __magic_name__      				=    1
       while repunit:
              __magic_name__      				=    (1_0 * repunit + 1) % divisor
              repunit_index += 1
       return repunit_index


def 							A						(				__snake_case: int = 1_0_0_0_0_0_0  )    ->		int:

       """simple docstring"""





       __magic_name__      				=    limit - 1
       if divisor % 2 == 0:
              divisor += 1
       while least_divisible_repunit(__snake_case  ) <= limit:
              divisor += 2
       return divisor


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