changed type of sum from int to long long int, program works past limit = 23000, but stops short of limit = 130000