From 6944d618d617bd41adbd4839cbfaac946f26bbf4 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Fri, 18 Jul 2025 00:13:05 +0800 Subject: [PATCH] feat: upate mod inv --- src/main/java/me/hatter/math/ModularInv.java | 32 ++++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/me/hatter/math/ModularInv.java b/src/main/java/me/hatter/math/ModularInv.java index 11b1f6d..eba518c 100644 --- a/src/main/java/me/hatter/math/ModularInv.java +++ b/src/main/java/me/hatter/math/ModularInv.java @@ -3,22 +3,6 @@ package me.hatter.math; import java.math.BigInteger; import java.util.Arrays; -// https://zhuanlan.zhihu.com/p/426499159 -// def modular_inv(a, p): -// x, y, m = 1, 0, p -// while a > 1: -// q = a // m -// t = m -// -// m = np.mod(a, m) -// a = t -// t = y -// -// y, x = x - np.int64(q) * np.int64(y), t -// -// if x < 0: -// x = np.mod(x, p) -// return np.mod(x, p) public class ModularInv { public static void main(String[] args) { @@ -42,6 +26,22 @@ public class ModularInv { } } + // https://zhuanlan.zhihu.com/p/426499159 + // def modular_inv(a, p): + // x, y, m = 1, 0, p + // while a > 1: + // q = a // m + // t = m + // + // m = np.mod(a, m) + // a = t + // t = y + // + // y, x = x - np.int64(q) * np.int64(y), t + // + // if x < 0: + // x = np.mod(x, p) + // return np.mod(x, p) public static BigInteger modularInv(BigInteger a, BigInteger p) { BigInteger x = BigInteger.ONE; BigInteger y = BigInteger.ZERO;