[root@devel3 root]# time ./trinum.pl >out real 0m41.310s user 0m41.310s sys 0m0.000s [root@devel3 root]# time ./trinum_c2.pl >out real 0m0.276s user 0m0.280s sys 0m0.000s [root@devel3 root]# more trinum_c2.pl #!/usr/bin/perl use Inline 'C'; my $file = $ARGV[0] || 'targets.txt'; open (INPUT, '<', $file) or die "Unable to open $file for reading : $!"; while ( ) { chomp; get_three( $_ ); } __END__ __C__ #include #define TRI(i) (i*(i+1)/2) int get_three ( int num ) { register max,target,i,j; max = (int)sqrt((double)(2*num)); while ( max != 0 ) { target = num - TRI(max); for( i=0;TRI(i)<=target;i++ ) { for( j=0;j<=i;j++ ) { if ( target == (int)(TRI(i)+TRI(j)) ) { printf( "%d, %d, %d\n", TRI(max), TRI(i), TRI(j) ); return 1; } } } max--; } printf( "Something went horribly wrong : %d\n", num ); return 0; } [root@devel3 root]#