def inv2(k:int) -> int:
    """ Return the inverse of 2 in :math:`\mathbb{Z}/3^k \mathbb{Z}`. \
        The element 2 can always be inverted in :math:`\mathbb{Z}/3^k \mathbb{Z}`. \
        It means for all :math:`k` there exists :math:`y\in\mathbb{Z}/3^k \mathbb{Z}` \
        such that :math:`2y = 1`. The value of :math:`y` is given by the formula :math:`\\frac{3^k+1}{2}`. 

    :Example:
        >>> inv2(2)
        5
        >>> inv2(3)
        14
    """
    return (3**k + 1)//2