/** * 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(); } } } } } } }
Get the answer
Category: business |
Author: Sagi Boris
Related Questions
/*question: how many times are the statements first semester and sec

// * answer with details* // quadrilateral abcd is inscribed in a circ

// answer pls // which of the following statements is true about mino

Category
mechanicalengineering
// marian basting takes in small sewing jobs. // she has two files sorted by date. // (the date is composed of two numbers -- month and year.) // one
biomedicalengineering
// please answer // how are plants called epiphytes adapted to living in the understory of a rainforest? a.) they have waxy leaves. b.) they lose the
science
// please answer \\ what is missing in the alpine tundra that is present in the arctic and antarctic tundra? a.) animals b.) permafrost c.) trees d.)