C version functionning (be careful not to explode RAM by running it on large inputs - I advise no more than 4 digits)