Completing legendre and adding factorial