modified prime algo