fact function

nearsq helper