Skip to content

Commit

Permalink
Use InternalMath.PowMod
Browse files Browse the repository at this point in the history
  • Loading branch information
kzrnm committed Jan 25, 2023
1 parent 7145d73 commit 5dc2e4a
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions Source/ac-library-csharp/Math/MathLib.PowMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@ public static partial class MathLib
/// </remarks>
[MethodImpl(256)]
public static long PowMod(long x, long n, int m)
{
Contract.Assert(0 <= n && 1 <= m, reason: $"0 <= {nameof(n)} && 1 <= {nameof(m)}");
if (m == 1) return 0;
Barrett barrett = new Barrett((uint)m);
uint r = 1, y = (uint)InternalMath.SafeMod(x, m);
while (0 < n)
{
if ((n & 1) != 0) r = barrett.Mul(r, y);
y = barrett.Mul(y, y);
n >>= 1;
}
return r;
}
=> InternalMath.PowMod(x, n, m);
}
}

0 comments on commit 5dc2e4a

Please sign in to comment.