feat: mod inv
This commit is contained in:
@@ -26,13 +26,16 @@ public class ModularInv {
|
||||
for (long j = 1; j < 10000; j++) {
|
||||
BigInteger a = BigInteger.valueOf(i);
|
||||
BigInteger p = BigInteger.valueOf(j);
|
||||
// gcd(a, p) = 1
|
||||
if (!a.gcd(p).equals(BigInteger.ONE)) {
|
||||
continue;
|
||||
}
|
||||
// a^-1 mod p
|
||||
BigInteger x = a.modInverse(p);
|
||||
BigInteger y = modularInv(a, p);
|
||||
System.out.println(Arrays.asList(a, p, a.modInverse(p), modularInv(a, p)));
|
||||
if (!y.equals(x)) {
|
||||
BigInteger z = a.modPow(Phi.phi(p).subtract(BigInteger.ONE), p);
|
||||
System.out.println(Arrays.asList(a + "^-1 mod " + p, x, y, z));
|
||||
if (!y.equals(x) || !y.equals(z)) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user