Java is implemented for BigInteger or BigDecimal. They are intended for really huge integers and decimal numbers, not extreme efficiency.
Low-level optimization is not the power of Java, so I would recommend abandoning Java. You can make an algorithm in C or even use Assembler. Then, if you need to use it in a Java application, you can always make it a library. Then using the Java Native Interface, you can use the library in your application.
source share