Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 2. (Ramanujan's Tari) Srinivasa Ramanujan was an Indian mathematician who became famous for his intuition for numbers. When the English mathematician G. H. Hardy
Problem 2. (Ramanujan's Tari) Srinivasa Ramanujan was an Indian mathematician who became famous for his intuition for numbers. When the English mathematician G. H. Hardy came to visit him one day, Hardy remarked that the number of his taxi was 1729, a rather dull number. To which Ramanujan replied, "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 Ramanujan1. java that accepts n (int) as command-line argument and writes to standard output all integers less than or equal to n that can be expressed as the sum of two cubes in two different ways. In other words, find distinct positive integers a, b, c, and d such that a3 + 63 = c3 + d' un. "/workspace/exercise4 $ java Ramanujan1 10000 1729 = 1 3 + 12 3 = 9-3 + 10-3 4104 = 23 16-3 3 = 9-3 + 15-3 Directions: . Use four nested for loops, with these bounds on the loop variables: 0 { 1 usage L5 private int i; // first number in the pair 1 usage private int j; // second number in the pair 3 usages private int sumOfCubes; // i^3 + j^3 // Constructs a pair (i, j). public Pair (int i, int j) { this. i = i; this . j = j; sumOfCubes = i * i * i + j * j * j; 5 6 // Returns a comparison of pairs this and other based on their sum-of-cubes values. 27 Of @ public int compareTo (Pair other) { return sumOfCubes - other . sumOfCubes; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started