subject

/** * Ramanujan. java
*
* S. Ramanujan was an Indian mathematician who became famous for his intuition
* for numbers. When the English mathematician G. H. Hardy came to visit him in
* the hospital one day, Hardy remarked that the number of his taxi was 1729, a
* rather dull number. To which Ramanujan replied, "No, Hardy! No, Hardy! It is
* a very interesting number. It is the smallest number expressible as the sum
* of two cubes in two different ways."
* Verify this claim by writing a program Ramanujan. java that takes a command
* line argument N and prints out all integers less than or equal to N that can
* be expressed as the sum of two cubes in two different ways - find distinct
* positive integers a, b, c, and d such that a^3 + b^3 = c^3 + d^3. Use four
* nested for loops.
*/
public class Ramanujan {
public static void main(String args[]) {
int N = Integer. parseInt(args[0]);
int a, b, c, d, a3, b3, c3, d3;
for (a = 1; a <= N; a++) {
a3 = a * a * a;
if (a3 > N) break;
for (b = a; b <= N; b++) {
b3 = b * b * b;
if (a3 + b3 > N) break;
for (c = a + 1; b <= N; c++) {
c3 = c * c * c;
if (c3 > a3 + b3) break;
for (d = c; d <= N; d++) {
d3 = d * d * d;
if (c3 + d3 > a3 + b3) break;
if (c3 + d3 == a3 + b3) {
System. out. print((a3+b3) + " = ");
System. out. print(a + "^3 + " + b + "^3 = ");
System. out. print(c + "^3 + " + d + "^3");
System. out. println();
}
}
}
}
}
}
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 14:30
Select the correct answer. sean is a computer programmer. he has programmed an application for toddlers that plays nursery rhymes. however, a logic error has occurred in the program. which problem is a likely consequence of the error? a. the program crashes every time the user wants to play the nursery rhymes. b. the program crosses its buffer boundaries and overwrites an adjacent program. c. the program plays a different nursery rhyme than the one the user intended to play. d. the program shows different structures in its programming language code. e. the program introduces new viruses every time the user plays a nursery rhyme.
Answers: 1
question
Computers and Technology, 23.06.2019 17:30
Write pseudocode to represent the logic of a program that allows the user to enter a value. the program multiplies the value by 10 and outputs the result.
Answers: 1
question
Computers and Technology, 24.06.2019 09:30
What is the definition of digital literacy?
Answers: 1
question
Computers and Technology, 24.06.2019 20:00
Avirus enters a computer or network as code embedded in other software directly from another computer
Answers: 1
You know the right answer?
/** * Ramanujan. java
*
* S. Ramanujan was an Indian mathematician who became famous fo...
Questions
question
History, 08.05.2021 01:00
question
Mathematics, 08.05.2021 01:00
question
Mathematics, 08.05.2021 01:00
question
Mathematics, 08.05.2021 01:00
question
Mathematics, 08.05.2021 01:00
Questions on the website: 13722361