#include #include #define UPPER 1004 //By Michael C. Bulboff and Jorge A. Cisneros// //April 2001// void main() { long M, L, S; long x, y, t, m; long a, b=0, n, d; long z; long counter = 0; long xlow, xhigh, ylow, yhigh, zlow, zhigh; long asize; long A[UPPER]; M = 30000001; //lower bound// L = 99999; S = M + L; //upper bound// asize = pow(S, 1.0/3.0) + 1; // we'll only need numbers up to the cube root of S // for(t=0; t <= asize; t++) { A[t]=t*t*t; //setting up the array// } for (m=M; m<= S; m++) { xlow = pow((double)(m/3), 1.0/3.0); xhigh = pow((double)(m), 1.0/3.0); xhigh = xhigh + 1; //lower and upper bounds of x// for(x=xlow; x<=xhigh; x++) { a = A[x]; ylow = (long) pow((m-a)/2, 1.0/3.0); yhigh = (long) pow((m-a), 1.0/3.0); yhigh = yhigh + 1; //upper and lower bounds for y// for(y=ylow; y<=yhigh; y++) { b = a + A[y]; z = m - b; for(t=0; t <= asize; t++) { // we now go thru the array of cubes // // if z = A[t] for some t, we increase the // // counter by one and break out of the loop // if((z==A[t])&&(t<=x)&&(t<=y)&&(y<=x)) { counter++; break; } if((z==A[t])&&(t<=x)&&(t<=y)&&(y<=x)) break; } // closes the t loop // if((z==A[t])&&(t<=x)&&(t<=y)&&(y<=x)) break; } // closes the y loop // if((z==A[t])&&(t<=x)&&(t<=y)&&(y<=x)) break; } // closes the x loop // } // closes the m loop // printf("counter = %d\n", counter); }