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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 02:30, jalaholmes2027
Three out of five seniors remain undecided about a college major at the end of their senior year.
Answers: 3
image
Computers and Technology, 23.06.2019 14:30, officialrogerfp3gf2s
Select the correct answer. a company wants to use online methods to target more customers. it decides to conduct a market research by collecting the data of a few customers with their consent. they want to track data of the sites that their customers frequently visit. which software can the company? a. spyware b. bots c. adware d. trojan horse e. rootkits
Answers: 1
image
Computers and Technology, 23.06.2019 21:50, Trinhphuongtran
Description: write function lastfirst() that takes one argument—a list of strings of the format "lastname, firstname" —and returns a list consisting of two lists: (a) a list of all the last names (b) a list of all the first names
Answers: 2
image
Computers and Technology, 24.06.2019 09:40, anyar
Healthy study habits are best described as
Answers: 1
You know the right answer?
/** * Ramanujan. java
*
* S. Ramanujan was an Indian mathematician who became famous fo...

Questions in other subjects:

Konu
Chemistry, 01.07.2020 15:01