View source code
Display the source code in std/math/exponential.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function std.math.exponential.powmod

Computes the value of a positive integer x, raised to the power n, modulo m.

Unqual!(Largest!(F,H)) powmod(F, G, H) (
  F x,
  G n,
  H m
)
if (isUnsigned!F && isUnsigned!G && isUnsigned!H);

Parameters

NameDescription
x base
n exponent
m modulus

Returns

x to the power n, modulo m. The return type is the largest of x's and m's type.

The function requires that all values have unsigned types.

Example

writeln(powmod(1U, 10U, 3U)); // 1
writeln(powmod(3U, 2U, 6U)); // 3
writeln(powmod(5U, 5U, 15U)); // 5
writeln(powmod(2U, 3U, 5U)); // 3
writeln(powmod(2U, 4U, 5U)); // 1
writeln(powmod(2U, 5U, 5U)); // 2

Authors

Walter Bright, Don Clugston, Conversion of CEPHES math library to D by Iain Buclaw and David Nadlinger

License

Boost License 1.0.