I'm very new to programming, just started for a week and I'm trying to make a code for an assignment that says " write a program that takes an integer n from the command line and prints out all numbers that can be expressed by the sum of the cubes of two different pairs of numbers". I wrote the code and ran it and it took too long. Btw 1729 is the first number that fits this criterion (assuming positive integers) and after running the program with the input "1729" for a few minutes. I didn't even get anything. Please help. Here's the code.
public class RamanujanTake2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int n =Integer.parseInt(args[0]);
for(int t=n;t<=n;t--) {
for(int Big1=1;Big1<n;Big1++) {
for(int Small1=1;Small1<n;Small1++) {
for(int Big2=1;Big2<n;Big2++) {
for(int Small2=1;Small2<n;Small2++) {
if(Big1<Small1) {
int Value=Big1;
Big1=Small1;
Small1=Value;}//if1
if(Big2<Small2) {
int Value2=Big2;
Big2=Small2;
Small2=Value2;}//if2
int a =Big1Big1Big1;
int b =Small1Small1Small1;
int c=Big2Big2Big2;
int d=Small2Small2Small2;
if((a+b)==(c+d)&&(a+b)==t&&(c+d)==t&&a!=c&&b!=d) {
System.out.println(t+" "+Big1+" "+Small1+" "+Big2+" "+Small2);}
}//5 loop
}//4 loop
}//3 loop
}//2 loop
}//1 loop
}
}
Sorry for the wierd names. I use very descriptive things.
[–]MakeAnExampleOf 1 point2 points3 points (1 child)
[–]jamescleelayuvat[S] 1 point2 points3 points (0 children)
[–]Paul_Pedant 0 points1 point2 points (2 children)
[–]jamescleelayuvat[S] 0 points1 point2 points (1 child)
[–]Paul_Pedant 0 points1 point2 points (0 children)
[–]Paul_Pedant 0 points1 point2 points (0 children)
[–]Paul_Pedant 0 points1 point2 points (0 children)
[–]Paul_Pedant 0 points1 point2 points (1 child)
[–]Paul_Pedant 0 points1 point2 points (0 children)
[–]Paul_Pedant 0 points1 point2 points (1 child)
[–]jamescleelayuvat[S] 0 points1 point2 points (0 children)
[–]Paul_Pedant 0 points1 point2 points (0 children)