

'''simple docstring'''






from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
      import torch

snake_case_       =       logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
      from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):


      def 					__lowerCamelCase			(      cls     :	List[str]    )							->   List[Any]:
            """simple docstring"""

            return cls


def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	Union[Tuple, List]  ,  SCREAMING_SNAKE_CASE_     :	Optional[Union[List["torch.Generator"], "torch.Generator"]] = None  ,  SCREAMING_SNAKE_CASE_     :	Optional["torch.device"] = None  ,  SCREAMING_SNAKE_CASE_     :	Optional["torch.dtype"] = None  ,  SCREAMING_SNAKE_CASE_     :	Optional["torch.layout"] = None  ,  )							->   List[Any]:
      """simple docstring"""

      SCREAMING_SNAKE_CASE_      :			List[Any]     =       device
      SCREAMING_SNAKE_CASE_      :			Optional[Any]     =       shape[0]

      SCREAMING_SNAKE_CASE_      :			Tuple     =       layout or torch.strided
      SCREAMING_SNAKE_CASE_      :			Tuple     =       device or torch.device("cpu"    )

      if generator is not None:
            SCREAMING_SNAKE_CASE_      :			Optional[int]     =       generator.device.type if not isinstance(SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_    ) else generator[0].device.type
            if gen_device_type != device.type and gen_device_type == "cpu":
                  SCREAMING_SNAKE_CASE_      :			List[str]     =       "cpu"
                  if device != "mps":
                        logger.info(
                            F"The passed generator was created on 'cpu' even though a tensor on {device} was expected."
                            F" Tensors will be created on 'cpu' and then moved to {device}. Note that one can probably"
                            F" slighly speed up this function by passing a generator that was created on the {device} device."    )
            elif gen_device_type != device.type and gen_device_type == "cuda":
                  raise ValueError(F"Cannot generate a {device} tensor from a generator of type {gen_device_type}."    )

      if isinstance(SCREAMING_SNAKE_CASE_  ,  SCREAMING_SNAKE_CASE_    ):
            SCREAMING_SNAKE_CASE_      :			List[Any]     =       (1,) + shape[1:]
            SCREAMING_SNAKE_CASE_      :			str     =       [
                torch.randn(SCREAMING_SNAKE_CASE_  ,  generator=generator[i]  ,  device=SCREAMING_SNAKE_CASE_  ,  dtype=SCREAMING_SNAKE_CASE_  ,  layout=SCREAMING_SNAKE_CASE_    )
                for i in range(SCREAMING_SNAKE_CASE_    )
            ]
            SCREAMING_SNAKE_CASE_      :			str     =       torch.cat(SCREAMING_SNAKE_CASE_  ,  dim=0    ).to(SCREAMING_SNAKE_CASE_    )
      else:
            SCREAMING_SNAKE_CASE_      :			Tuple     =       torch.randn(SCREAMING_SNAKE_CASE_  ,  generator=SCREAMING_SNAKE_CASE_  ,  device=SCREAMING_SNAKE_CASE_  ,  dtype=SCREAMING_SNAKE_CASE_  ,  layout=SCREAMING_SNAKE_CASE_    ).to(SCREAMING_SNAKE_CASE_    )

      return latents





def 					__lowerCamelCase			(      SCREAMING_SNAKE_CASE_     :	str    )							->   str:
      """simple docstring"""

      if is_torch_version("<"  ,  "2.0.0"    ) or not hasattr(SCREAMING_SNAKE_CASE_  ,  "_dynamo"    ):
            return False
      return isinstance(SCREAMING_SNAKE_CASE_  ,  torch._dynamo.eval_frame.OptimizedModule    )






from __future__ import annotations



def        __a     (    lowerCAmelCase_   :					int				)      -> int | None:






						'''simple docstring'''



						for r in range(1			,lowerCAmelCase_				):
												UpperCAmelCase_=   []
												for x in range(n - 1				):
																		UpperCAmelCase_=   pow(lowerCAmelCase_			,lowerCAmelCase_			,lowerCAmelCase_				)
																		if val in li:
																								break
																		li.append(lowerCAmelCase_				)
												else:
																		return r
						return None


if __name__ == "__main__":
	__A				    =						int(input('''Enter a prime number q: '''))
	__A				    =						find_primitive(q)
	if a is None:
		print(f'Cannot find the primitive for the value: {a!r}')
	else:
		__A				    =						int(input('''Enter private key of A: '''))
		__A				    =						pow(a, a_private, q)
		__A				    =						int(input('''Enter private key of B: '''))
		__A				    =						pow(a, b_private, q)

		__A				    =						pow(b_public, a_private, q)
		__A				    =						pow(a_public, b_private, q)

		print('''The key value generated by A is: ''', a_secret)
		print('''The key value generated by B is: ''', b_secret)




