Add IsPerfect and make IsPrime more efficient