after test of n. Remove potential for undefined behaviour (INT_MIN-1) by making limit an unsigned long.