In Int§

See primary documentation in context for routine expmod

multi        expmod(      $x,     $y,     $mod --> Int:D)
multi        expmod(Int:D $x, Int $y, Int $mod --> Int:D)
multi method expmod(Int:D:    Int $y, Int $mod --> Int:D)

Returns the given Int raised to the $y power within modulus $mod, that is gives the result of ($x ** $y) mod $mod. The subroutine form can accept non-Int arguments, which will be coerced to Int.

say expmod(4, 2, 5);    # OUTPUT: «1␤»
say 7.expmod(2, 5);     # OUTPUT: «4␤»

$y argument can also be negative, in which case, the result is equivalent to ($x ** $y) mod $mod.

say 7.expmod(-2, 5);     # OUTPUT: «4␤»