Skip to content

Commit 96b80b5

Browse files
committed
improve barret algorithm atcoder/ac-library#163
1 parent 960a0e8 commit 96b80b5

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

Source/ac-library-csharp/Math/Internal/Barrett.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ public Barrett(uint m)
2626
public uint Reduce(ulong z)
2727
{
2828
var x = InternalMath.Mul128Bit(z, IM);
29-
var v = unchecked((uint)(z - x * Mod));
30-
if (Mod <= v) v += Mod;
31-
return v;
29+
var y = x * Mod;
30+
return (uint)(z - y + (z < y ? Mod : 0));
3231
}
3332

3433
/// <summary>

0 commit comments

Comments
 (0)