From Wikipedia:

In modular arithmetic,   the modular multiplicative inverse of an integer    a    modulo    m    is an integer    x    such that





a

x
≡
1


(
mod

m
)

.


{\displaystyle a\,x\equiv 1{\pmod {m}}.}


Or in other words, such that:





∃
k
∈

Z

,

a

x
=
1
+
k

m


{\displaystyle \exists k\in \mathbb {Z} ,\qquad a\,x=1+k\,m}


It can be shown that such an inverse exists   if and only if    a    and    m    are coprime,   but we will ignore this for this task.



Task

Either by implementing the algorithm, by using a dedicated library or by using a built-in function in
your language,   compute the modular inverse of   42 modulo 2017.




            NORMAL MODE IS INTEGER
            INTERNAL FUNCTION(AA, BB)
            ENTRY TO MULINV.
            A = AA
            B = BB 
            WHENEVER B.L.0, B = -B
            WHENEVER A.L.0, A = B - (-(A-A/B*B))
            T = 0
            NT = 1
            R = B
            NR = A-A/B*B
LOOP        WHENEVER NR.NE.0
                Q = R/NR
                TMP = NT
                NT = T - Q*NT
                T = TMP
                TMP = NR
                NR = R - Q*NR
                R = TMP
                TRANSFER TO LOOP
            END OF CONDITIONAL
            WHENEVER R.G.1, FUNCTION RETURN -1
            WHENEVER T.L.0, T = T+B
            FUNCTION RETURN T
            END OF FUNCTION
 
            INTERNAL FUNCTION(AA, BB)
            VECTOR VALUES FMT = $I5,2H, ,I5,2H: ,I5*$
            ENTRY TO SHOW.
            PRINT FORMAT FMT, AA, BB, MULINV.(AA, BB)
            END OF FUNCTION
 
            SHOW.(42,2017)
            SHOW.(40,1)
            SHOW.(52,-217)
            SHOW.(-486,217)
            SHOW.(40,2018)
            END OF PROGRAM