Question: Problem 9 - Bonus points ( Ramanujan Number ) Srinivasa Ramanujan was an Indian mathematician who became famous for his intu - ition for numbers.

Problem 9- Bonus points (
Ramanujan Number
)
Srinivasa Ramanujan
was an Indian mathematician who became famous for his intu-
ition 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 named
ramanujan.cpp
that accepts
n
(int) from
command-line arguments 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
a
3
+
b
3
=
c
3
+
d
3
n
.
Your program should report the message
Invalid value of n
if
n
0
/workspace/csc117/hw7
% g++-o out/ramanujan.out src/ramanujan.cpp
%./out/ramanujan.out 30000
1729=1^3+12^3=9^3+10^3
4104=2^3+16^3=9^3+15^3
6
13832=2^3+24^3=18^3+20^3
20683=10^3+27^3=19^3+24^3
%./out/ramanujan.out -10000
Invalid value of N
Hins:
Use four nested
for
loops with these bounds on the loops variables: 0
< a
3
n
,
a < b
3
n
a
3
,
a < c
3
n
, and
c < d
3
n
c
3
.
Do not explicitly compute cube roots use
x*x*x < y
instead of using
x < cbrt(y)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!