When I run the program with x = 999
then it finishes under 22s. But I need to go more than 9999999
. When put x = 9999
then it takes a long time. I opened my laptop for 7 hours. So, can make it faster?
I tried with python and also javascript. those took longer than c.
#include <stdio.h>
#include <math.h>
int main() {
signed long int x = 999;
signed long int target = 43;
signed long int a = ((-1) * x);
signed long int b = ((-1) * x);
signed long int c = ((-1) * x);
signed long int cheack = ((a * a * a) + (b * b * b) + (c * c * c));
signed long int sum_Max = pow(((x * 2) + 1), 3);
printf("Max SUM: %ld\n", sum_Max);
while (cheack != target) {
signed long int cheack = ((a * a * a) + (b * b * b) + (c * c * c));
if (cheack == target) {
printf("Available: \n");
printf(" a = %ld \n", a);
printf(" b = %ld \n", b);
printf(" c = %ld \n", c);
printf(" target = %ld ", target);
break;
} else if (a == x) {
if (b == x) {
if (c == x) {
printf("Not available... Try in bigger numbers");
break;
} else {
a = ((-1) * x);
b = ((-1) * x);
c++;
}
} else {
a = ((-1) * x);
b++;
}
} else {
a++;
}
}
return 0;
}
I need to complete this project please try to fix the problem.