factorial with boundary