
from __future__ import annotations

def a__   (	UpperCAmelCase__,					UpperCAmelCase__,					UpperCAmelCase__ ):






  '''simple docstring'''





  assert n > 1 and a > 0 and greatest_common_divisor(lowercase_,					lowercase_ ) == 1
  ((__magic_name__)					,   (__magic_name__)					,   (__magic_name__))    					=	extended_gcd(lowercase_,					lowercase_ )  # Implemented below
  __magic_name__    					=	(b * s) % n
  return x

def a__   (	UpperCAmelCase__,					UpperCAmelCase__ ):






  '''simple docstring'''





  ((__magic_name__)					,   (__magic_name__))    					=	extended_euclid(lowercase_,					lowercase_ )  # Implemented below
  if b < 0:
    __magic_name__    					=	(b % n + n) % n
  return b

def a__   (	UpperCAmelCase__,					UpperCAmelCase__,					UpperCAmelCase__ ):






  '''simple docstring'''





  __magic_name__    					=	invert_modulo(lowercase_,					lowercase_ )
  __magic_name__    					=	(b * s) % n
  return x

def a__   (	UpperCAmelCase__,					UpperCAmelCase__ ):






  '''simple docstring'''





  assert a >= 0 and b >= 0

  if b == 0:
    __magic_name__					,   __magic_name__					,   __magic_name__    					=	a, 1, 0
  else:
    ((__magic_name__)					,   (__magic_name__)					,   (__magic_name__))    					=	extended_gcd(lowercase_,					a % b )
    __magic_name__    					=	q
    __magic_name__    					=	p - q * (a // b)

  assert a % d == 0 and b % d == 0
  assert d == a * x + b * y

  return (d, x, y)

def a__   (	UpperCAmelCase__,					UpperCAmelCase__ ):






  '''simple docstring'''





  if b == 0:
    return (1, 0)
  ((__magic_name__)					,   (__magic_name__))    					=	extended_euclid(lowercase_,					a % b )
  __magic_name__    					=	a // b
  return (y, x - k * y)

def a__   (	UpperCAmelCase__,					UpperCAmelCase__ ):






  '''simple docstring'''





  if a < b:
    __magic_name__					,   __magic_name__    					=	b, a

  while a % b != 0:
    __magic_name__					,   __magic_name__    					=	b, a % b

  return b


if __name__ == "__main__":
    from doctest import testmod

    testmod(name='modular_division', verbose=True)
    testmod(name='modular_division2', verbose=True)
    testmod(name='invert_modulo', verbose=True)
    testmod(name='extended_gcd', verbose=True)
    testmod(name='extended_euclid', verbose=True)
    testmod(name='greatest_common_divisor', verbose=True)



from itertools import compress, repeat
from math import ceil, sqrt

def a__   (	A_ ):






  '''simple docstring'''





  if num <= 2:
    return []
  if num == 3:
    return [2]

  # Odd sieve for numbers in range [3, num - 1]
  __magic_name__    					=	bytearray(b"""\x01""" ) * ((num >> 1) - 1)

  for i in range(3,					int(sqrt(A_ ) ) + 1,					2 ):
    if sieve[(i >> 1) - 1]:
      __magic_name__    					=	i**2
      __magic_name__    					=	repeat(
          0,					ceil((num - i_squared) / (i << 1) ) )

  return [2] + list(compress(range(3,					A_,					2 ),					A_ ) )


if __name__ == "__main__":
    import doctest

    doctest.testmod()

