fergal,
I had a copy/paste error which was the source of a whole lot of problems originally. I left j as type double and updated the printf() format as ".0f" but your way works too. I also had a missing hyphen from -fomit-frame-pointer which I corrected.
I have run this code on my machine and it finished in 53.5 minutes. I am not really shocked by this but I am impressed. The only optimizations the C code attempts to make is by limiting the number of the 17 trillion different sets it visits. Adding in a cache and some other neat doo-dads could probably blow this 53.5 minutes out of the water - but why bother. That is one of the beauties of Perl. The amount of time it would take to devise a C program to beat the Perl is more than time than it takes the Perl to run. Good Job.