Reputation: 67
How would I go about this n Java?
double power = (Math.pow(11,-1)) % 26;
System.out.println(power);
Just returns 0.09090909090909091
. According to wolfram
Thanks!
Upvotes: 1
Views: 1686
Reputation: 9319
Wolframalfa doesn't interpret your syntax as expected. Instead of writing
11^-1 mod 26
try
mod(11^-1, 26)
which will return the same result as your Java snippet.
Upvotes: 1
Reputation: 123490
Java is technically correct, the inverse of 11 mod 26 is (approximately) 0.09090909090909 because 0.09090909090909 * 11 is approximately 1, whether mod 26 or not.
However, what you're trying to find is an integer with the same property, 19, because 19*11 = 1 mod 26, and you can't do that with the same approach.
Fortunately, the standard library has you covered:
import java.math.BigInteger;
class Test {
public static void main(String[] args) {
System.out.println(
new BigInteger("11").modInverse(new BigInteger("26")));
}
}
Upvotes: 7