#include #include #define UPPER 1004 void main() { long M, L, S; long x, y, t, m; long a, b=0, n, d; long z; long count = 0, solutions = 0, counter = 0; long total = 0, total2 = 0, total3 = 0; long xlow, xhigh, ylow, yhigh, zlow, zhigh; long asize; long A[UPPER]; //setting up the array// M = 22900001; //lower bound// L = 99999; S = M + L; //upper bound// asize = pow(S, 1.0/3.0) + 1; for(t=0; t <= asize; t++) { A[t]=t*t*t; } // creates an array of cubes up to asize // 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; //upper and lower bounds for 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++) { if((z==A[t])&&(t<=x)&&(t<=y)&&(y<=x)) { if((x==y)&&(x==z)&&(y==z)) solutions++; else if((x==y)||(x==z)||(y==z)) solutions+=3; else solutions+=6; break; //calculating R3(m). These are the permutations.// //If x=y=z, one distinct permutation// //If x=y or x=z or y=z, three permutations// //If x,y, and z unique, six distinct permutations// } //closes the IF loop// }//closes the t loop// } //closes the y loop// } //closes the x loop// if(solutions!=0) { counter++; total = total + solutions; //sum of R3(m) over [M, M+L]// total2 = total2 + solutions*solutions;//sum of R3(m)^2// total3 = total3 + solutions*solutions*solutions; solutions = 0;//resetting R3(m) for the next m// }//closes the IF loop// } //closes the m loop// printf("Y3(m) Total = %d\n", counter); printf("R3(m) Total = %d\n", total); printf("R3(m) Squared Total = %d\n", total2); printf("R3(m) Cubed Total = %d\n", total3); }