Refactored java and scala code to the same place and factored out PrimeCache, solved p29