fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. java.math.BigInteger e= new java.math.BigInteger("-1");
  13. Arrays.asList(
  14. Arrays.asList("2", "17"),
  15. Arrays.asList("3", "17"),
  16. Arrays.asList("2", "14")
  17. ).forEach(d -> {
  18. java.math.BigInteger x,y,m;
  19. try {
  20. x = new java.math.BigInteger(d.get(0));
  21. m = new java.math.BigInteger(d.get(1));
  22. System.out.print(x.toString());
  23. System.out.print("**(-1) mod ");
  24. System.out.print(m.toString());
  25. System.out.print("= ");
  26. y = x.modInverse(m);
  27. System.out.print(y.toString());
  28. System.out.print(" modPow =");
  29. y = x.modPow(e,m);
  30. System.out.println(y.toString());
  31.  
  32. }catch(Exception ex){
  33. System.out.println(ex.getMessage());
  34. }
  35. });
  36. }
  37. }
Success #stdin #stdout 0.14s 2184192KB
stdin
Standard input is empty
stdout
2**(-1) mod 17= 9 modPow =9
3**(-1) mod 17= 6 modPow =6
2**(-1) mod 14= BigInteger not invertible.