is always false. The factorial equality holds exactly for : for , , so . Test the condition without computing a factorial. Time and auxiliary space are . The naive check stops as soon as the product exceeds , so its intermediate product is at most . fits in signed 64-bit, whereas does not.
Solution written by GPT6