


from __future__ import annotations

from typing import Any





class   __a      :
 def __init__(       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__    ,			lowerCAmelCase__ = 0			) ->    None:




        '''simple docstring'''
        lowercase__      ,						lowercase__:       str        =       row, column
        lowercase__:       Optional[Any]        =       [[default_value for c in range(lowerCAmelCase__			)] for r in range(lowerCAmelCase__			)]
 def __str__(       self			) ->    str:




        '''simple docstring'''
        lowercase__:       List[str]        =       F'Matrix consist of {self.row} rows and {self.column} columns\n'

        # Make string identifier
        lowercase__:       str        =       0
        for row_vector in self.array:
               for obj in row_vector:
                      lowercase__:       List[Any]        =       max(lowerCAmelCase__    ,			len(str(lowerCAmelCase__			)			)			)
        lowercase__:       Any        =       F'%{max_element_length}s'

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

        s += "\n".join(single_line(lowerCAmelCase__			) for row_vector in self.array			)
        return s
 def __repr__(       self			) ->    str:




        '''simple docstring'''
        return str(self			)
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__			) ->    bool:




        '''simple docstring'''
        if not (isinstance(lowerCAmelCase__    ,			(list, tuple)			) and len(lowerCAmelCase__			) == 2):
               return False
        elif not (0 <= loc[0] < self.row and 0 <= loc[1] < self.column):
               return False
        else:
               return True
 def __getitem__(       self    ,			lowerCAmelCase__			) ->    Any:




        '''simple docstring'''
        assert self.validate_indicies(lowerCAmelCase__			)
        return self.array[loc[0]][loc[1]]
 def __setitem__(       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    None:




        '''simple docstring'''
        assert self.validate_indicies(lowerCAmelCase__			)
        lowercase__:       str        =       value
 def __add__(       self    ,			lowerCAmelCase__			) ->    Matrix:




        '''simple docstring'''
        assert isinstance(lowerCAmelCase__    ,			lowerCAmelCase__			)
        assert self.row == another.row and self.column == another.column

        # Add
        lowercase__:       Tuple        =       Matrix(self.row    ,			self.column			)
        for r in range(self.row			):
               for c in range(self.column			):
                      lowercase__:       Dict        =       self[r, c] + another[r, c]
        return result
 def __neg__(       self			) ->    Matrix:




        '''simple docstring'''
        lowercase__:       Optional[int]        =       Matrix(self.row    ,			self.column			)
        for r in range(self.row			):
               for c in range(self.column			):
                      lowercase__:       Union[str, Any]        =       -self[r, c]
        return result
 def __sub__(       self    ,			lowerCAmelCase__			) ->    Matrix:




        '''simple docstring'''
        return self + (-another)
 def __mul__(       self    ,			lowerCAmelCase__			) ->    Matrix:




        '''simple docstring'''

        if isinstance(lowerCAmelCase__    ,			(int, float)			):  # Scalar multiplication
               lowercase__:       Dict        =       Matrix(self.row    ,			self.column			)
               for r in range(self.row			):
                      for c in range(self.column			):
                             lowercase__:       Dict        =       self[r, c] * another
               return result
        elif isinstance(lowerCAmelCase__    ,			lowerCAmelCase__			):  # Matrix multiplication
               assert self.column == another.row
               lowercase__:       Optional[int]        =       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:
               lowercase__:       Optional[Any]        =       F'Unsupported type given for another ({type(lowerCAmelCase__			)})'
               raise TypeError(lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Matrix:




        '''simple docstring'''
        lowercase__:       List[Any]        =       Matrix(self.column    ,			self.row			)
        for r in range(self.row			):
               for c in range(self.column			):
                      lowercase__:       int        =       self[r, c]
        return result
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    Any:




        '''simple docstring'''
        assert isinstance(lowerCAmelCase__    ,			lowerCAmelCase__			) and isinstance(lowerCAmelCase__    ,			lowerCAmelCase__			)
        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
        lowercase__:       Any        =       v.transpose()
        lowercase__:       List[Any]        =       (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        snake_case_					(  )  ->    None:
        # a^(-1)
        lowercase__:       Any        =       Matrix(3      ,							3      ,							0					)
        for i in range(3					):
               lowercase__:       Optional[Any]        =       1
        print(f'a^(-1) is {ainv}'					)
        # u, v
        lowercase__:       Any        =       Matrix(3      ,							1      ,							0					)
        lowercase__      ,						lowercase__      ,						lowercase__:       Any        =       1, 2, -3
        lowercase__:       List[Any]        =       Matrix(3      ,							1      ,							0					)
        lowercase__      ,						lowercase__      ,						lowercase__:       str        =       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(snake_case      ,							snake_case					)}'					)




 def        snake_case_					(  )  ->    None:
        import doctest

        doctest.testmod()




 testa()






from __future__ import annotations




def        snake_case_					(  snake_case      ,							snake_case					)  ->    list[str]:
       if nth_term == "":
              return [""]
       lowercase__:       Tuple        =       int(snake_case					)
       lowercase__:       int        =       int(snake_case					)
       lowercase__:       list[str]        =       []
       for temp in range(int(snake_case					)					):
              series.append(f'1 / {pow(temp + 1      ,							int(snake_case					)					)}' if series else '1'					)
       return series


if __name__ == "__main__":
 import doctest

 doctest.testmod()

 __lowerCAmelCase			=							int(input('''Enter the last number (nth term) of the P-Series'''))
 __lowerCAmelCase			=							int(input('''Enter the power for  P-Series'''))
 print('''Formula of P-Series => 1+1/2^p+1/3^p ..... 1/n^p''')
 print(p_series(nth_term, power))


