I found an error in my code when trying to check if 31219483 is prime. Originally I had the line
a=int(Long.remainderUnsigned((long)a*a, n));