The original code added 3 in this line
slope = slope.add(new BigInteger("3"));
But it should be adding a
, so replace it with this line
slope = slope.add(a);
where a
is
static BigInteger a = new BigInteger("6277101735386680763835789423207666416083908700390324961276");
Then you'll get
Doubling is correct
when you run main function.