feat: euler theorem
This commit is contained in:
@@ -2,7 +2,7 @@ package me.hatter.math;
|
|||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
|
|
||||||
public class Phi {
|
public class EulerTheorem {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
for (long x = 4; x < 10000; x++) {
|
for (long x = 4; x < 10000; x++) {
|
||||||
@@ -18,7 +18,7 @@ public class ModularInv {
|
|||||||
BigInteger x = a.modInverse(p);
|
BigInteger x = a.modInverse(p);
|
||||||
BigInteger y = modularInv(a, p);
|
BigInteger y = modularInv(a, p);
|
||||||
// a^(phi(p)-1) mod 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));
|
System.out.println(Arrays.asList(a + "^-1 mod " + p, x, y, z));
|
||||||
if (!y.equals(x) || !y.equals(z)) {
|
if (!y.equals(x) || !y.equals(z)) {
|
||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
|
|||||||
Reference in New Issue
Block a user