Speed improvement in prime calculation