





from __future__ import annotations

from typing import Any



class  A__       :





      def __init__(			self	,							A_	,							A_	,							A_ = 0       ):
       '''simple docstring'''




       UpperCamelCase     ,   UpperCamelCase     : Optional[Any]	     =       row, column
       UpperCamelCase     : Optional[Any]	     =       [[default_value for c in range(A_       )] for r in range(A_       )]





      def __str__(			self       ):
       '''simple docstring'''




       UpperCamelCase     : List[str]	     =       F"""Matrix consist of {self.row} rows and {self.column} columns\n"""

       # Make string identifier
       UpperCamelCase     : int	     =       0
       for row_vector in self.array:
        for obj in row_vector:
         UpperCamelCase     : Any	     =       max(A_	,							len(str(A_       )       )       )
       UpperCamelCase     : str	     =       F"""%{max_element_length}s"""

       # Make string and return
       def single_line(A_       ) -> str:
        nonlocal string_format_identifier
        UpperCamelCase     : List[str]	     =       "["
        line += ", ".join(string_format_identifier % (obj,) for obj in row_vector       )
        line += "]"
        return line

       s += "\n".join(single_line(A_       ) for row_vector in self.array       )
       return s





      def __repr__(			self       ):
       '''simple docstring'''




       return str(self       )





      def 	__UpperCamelCase(			self	,							A_       ):
       '''simple docstring'''




       if not (isinstance(A_	,							(list, tuple)       ) and len(A_       ) == 2):
        return False
       elif not (0 <= loc[0] < self.row and 0 <= loc[1] < self.column):
        return False
       else:
        return True





      def __getitem__(			self	,							A_       ):
       '''simple docstring'''




       assert self.validate_indicies(A_       )
       return self.array[loc[0]][loc[1]]





      def __setitem__(			self	,							A_	,							A_       ):
       '''simple docstring'''




       assert self.validate_indicies(A_       )
       UpperCamelCase     : Dict	     =       value





      def __add__(			self	,							A_       ):
       '''simple docstring'''




       assert isinstance(A_	,							A_       )
       assert self.row == another.row and self.column == another.column

       # Add
       UpperCamelCase     : List[str]	     =       Matrix(self.row	,							self.column       )
       for r in range(self.row       ):
        for c in range(self.column       ):
         UpperCamelCase     : List[Any]	     =       self[r, c] + another[r, c]
       return result





      def __neg__(			self       ):
       '''simple docstring'''




       UpperCamelCase     : List[Any]	     =       Matrix(self.row	,							self.column       )
       for r in range(self.row       ):
        for c in range(self.column       ):
         UpperCamelCase     : List[str]	     =       -self[r, c]
       return result





      def __sub__(			self	,							A_       ):
       '''simple docstring'''




       return self + (-another)





      def __mul__(			self	,							A_       ):
       '''simple docstring'''




       if isinstance(A_	,							(int, float)       ):  # Scalar multiplication
        UpperCamelCase     : List[str]	     =       Matrix(self.row	,							self.column       )
        for r in range(self.row       ):
         for c in range(self.column       ):
          UpperCamelCase     : List[str]	     =       self[r, c] * another
        return result
       elif isinstance(A_	,							A_       ):  # Matrix multiplication
        assert self.column == another.row
        UpperCamelCase     : Union[str, Any]	     =       Matrix(self.row	,							another.column       )
        for r in range(self.row       ):
         for c in range(another.column       ):
          for i in range(self.column       ):
           result[r, c] += self[r, i] * another[i, c]
        return result
       else:
        UpperCamelCase     : List[str]	     =       F"""Unsupported type given for another ({type(A_       )})"""
        raise TypeError(A_       )





      def 	__UpperCamelCase(			self       ):
       '''simple docstring'''




       UpperCamelCase     : Optional[int]	     =       Matrix(self.column	,							self.row       )
       for r in range(self.row       ):
        for c in range(self.column       ):
         UpperCamelCase     : List[str]	     =       self[r, c]
       return result





      def 	__UpperCamelCase(			self	,							A_	,							A_       ):
       '''simple docstring'''




       assert isinstance(A_	,							A_       ) and isinstance(A_	,							A_       )
       assert self.row == self.column == u.row == v.row  # u, v should be column vector
       assert u.column == v.column == 1  # u, v should be column vector

       # Calculate
       UpperCamelCase     : Tuple	     =       v.transpose()
       UpperCamelCase     : int	     =       (v_t * self * u)[0, 0] + 1
       if numerator_factor == 0:
        return None  # It's not invertable
       return self - ((self * u) * (v_t * self) * (1.0 / numerator_factor))


# Testing
if __name__ == "__main__":



    def 		A_    (					)						->			int:






     """simple docstring"""




     UpperCamelCase     : Tuple	     =       Matrix(3							,       3							,       0					)
     for i in range(3					):
      UpperCamelCase     : int	     =       1
     print(F"""a^(-1) is {ainv}"""					)
     # u, v
     UpperCamelCase     : List[str]	     =       Matrix(3							,       1							,       0					)
     UpperCamelCase     ,   UpperCamelCase     ,   UpperCamelCase     : Union[str, Any]	     =       1, 2, -3
     UpperCamelCase     : Tuple	     =       Matrix(3							,       1							,       0					)
     UpperCamelCase     ,   UpperCamelCase     ,   UpperCamelCase     : Union[str, Any]	     =       4, -2, 5
     print(F"""u is {u}"""					)
     print(F"""v is {v}"""					)
     print(F"""uv^T is {u * v.transpose()}"""					)
     # Sherman Morrison
     print(F"""(a + uv^T)^(-1) is {ainv.sherman_morrison(_lowerCAmelCase							,       _lowerCAmelCase					)}"""					)



    def 		A_    (					)						->			str:






     """simple docstring"""




     import doctest

     doctest.testmod()


    testa()







import math



def 		A_    (					_lowerCAmelCase					)						->			list:
 UpperCamelCase     : str	     =       [True] * n
 UpperCamelCase     : Optional[int]	     =       False
 UpperCamelCase     : str	     =       False
 UpperCamelCase     : List[Any]	     =       True

 for i in range(3							,       int(n**0.5 + 1					)							,       2					):
  UpperCamelCase     : int	     =       i * 2
  while index < n:
   UpperCamelCase     : Optional[Any]	     =       False
   UpperCamelCase     : Optional[Any]	     =       index + i

 UpperCamelCase     : Optional[Any]	     =       [2]

 for i in range(3							,       _lowerCAmelCase							,       2					):
  if is_prime[i]:
   primes.append(_lowerCAmelCase					)

 return primes



def 		A_    (					_lowerCAmelCase = 9999_6666_3333					)						->			int:
 UpperCamelCase     : Tuple	     =       math.floor(math.sqrt(_lowerCAmelCase					)					) + 100
 UpperCamelCase     : Dict	     =       prime_sieve(_lowerCAmelCase					)

 UpperCamelCase     : Optional[Any]	     =       0
 UpperCamelCase     : Tuple	     =       0
 UpperCamelCase     : List[str]	     =       primes[prime_index]

 while (last_prime**2) <= limit:
  UpperCamelCase     : Dict	     =       primes[prime_index + 1]

  UpperCamelCase     : Any	     =       last_prime**2
  UpperCamelCase     : Union[str, Any]	     =       next_prime**2

  # Get numbers divisible by lps(current)
  UpperCamelCase     : Dict	     =       lower_bound + last_prime
  while upper_bound > current <= limit:
   matches_sum += current
   current += last_prime

  # Reset the upper_bound
  while (upper_bound - next_prime) > limit:
   upper_bound -= next_prime

  # Add the numbers divisible by ups(current)
  UpperCamelCase     : List[str]	     =       upper_bound - next_prime
  while current > lower_bound:
   matches_sum += current
   current -= next_prime

  # Remove the numbers divisible by both ups and lps
  UpperCamelCase     : Dict	     =       0
  while upper_bound > current <= limit:
   if current <= lower_bound:
    # Increment the current number
    current += last_prime * next_prime
    continue

   if current > limit:
    break

   # Remove twice since it was added by both ups and lps
   matches_sum -= current * 2

   # Increment the current number
   current += last_prime * next_prime

  # Setup for next pair
  UpperCamelCase     : str	     =       next_prime
  prime_index += 1

 return matches_sum


if __name__ == "__main__":
    print(solution())
