Skip to content

Commit

Permalink
improve barret algorithm atcoder/ac-library#163
Browse files Browse the repository at this point in the history
  • Loading branch information
kzrnm committed May 5, 2023
1 parent 960a0e8 commit 96b80b5
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Source/ac-library-csharp/Math/Internal/Barrett.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ public Barrett(uint m)
public uint Reduce(ulong z)
{
var x = InternalMath.Mul128Bit(z, IM);
var v = unchecked((uint)(z - x * Mod));
if (Mod <= v) v += Mod;
return v;
var y = x * Mod;
return (uint)(z - y + (z < y ? Mod : 0));
}

/// <summary>
Expand Down

0 comments on commit 96b80b5

Please sign in to comment.