feat: euler theorem

This commit is contained in:
2025-07-18 06:58:29 +08:00
parent bdaec5198b
commit 00b2c67975
2 changed files with 2 additions and 2 deletions

View File

@@ -2,7 +2,7 @@ package me.hatter.math;
import java.math.BigInteger;
public class Phi {
public class EulerTheorem {
public static void main(String[] args) {
for (long x = 4; x < 10000; x++) {

View File

@@ -18,7 +18,7 @@ public class ModularInv {
BigInteger x = a.modInverse(p);
BigInteger y = modularInv(a, p);
// a^(phi(p)-1) mod p
BigInteger z = a.modPow(Phi.phi(p).subtract(BigInteger.ONE), p);
BigInteger z = a.modPow(EulerTheorem.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();