Skip to content

Instantly share code, notes, and snippets.

@t81lal
Created July 30, 2015 17:44
Show Gist options
  • Save t81lal/08a3f3b3bb9c6df71e34 to your computer and use it in GitHub Desktop.
Save t81lal/08a3f3b3bb9c6df71e34 to your computer and use it in GitHub Desktop.
private static long inverse(long k, boolean long_) {
try {
if(!long_) {
k = (int)k;
}
final BigInteger num = BigInteger.valueOf(k);
return num.modInverse(new BigInteger(String.valueOf(1L << (long_ ? 64 : 32)))).longValue();
} catch (final Exception e) {
e.printStackTrace();
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment