inv[x] = ( Mod - Mod / x ) * inv[Mod%x] % Mod
设Mod=px+q. inv[x]=r
px+q = 0 (mod Mod)
pxr+qr = 0 (mod Mod)
p + qr = 0 (mod Mod)
r=-p/q= -p*inv[q] = -(Mod/x)*inv[Mod % x] = (Mod - Mod/x) * inv[Mod % x].
时间: 2024-10-08 19:55:56
inv[x] = ( Mod - Mod / x ) * inv[Mod%x] % Mod
设Mod=px+q. inv[x]=r
px+q = 0 (mod Mod)
pxr+qr = 0 (mod Mod)
p + qr = 0 (mod Mod)
r=-p/q= -p*inv[q] = -(Mod/x)*inv[Mod % x] = (Mod - Mod/x) * inv[Mod % x].