Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Ramanujan numbers. When the English mathematician G. H. Hardy came to visit the Indian mathematician Srinivasa Ramanujan in the hospital one day, Hardy remarked that

  1. Ramanujan numbers. When the English mathematician G. H. Hardy came to visit the Indian mathematician Srinivasa Ramanujan 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.

    An integer n is a Ramanujan number if can be expressed as the sum of two positive cubes in two different ways. That is, there are four distinct positive integers a, b, c, and d such that n=a3+b3=c3+d3n=a3+b3=c3+d3. For example 1729=13+123=93+1031729=13+123=93+103.

    Write a program Ramanujan.java that takes a long integer command-line argument n and prints true if it is a Ramanujan number, and falseotherwise. To do so, organize your program according to the following public API:

    public class Ramanujan { // Is n a Ramanujan number? public static boolean isRamanujan(long n) // Takes a long integer command-line arguments n and prints true if // n is a Ramanujan number, and false otherwise. public static void main(String[] args) } 

    Here are a few sample executions:

    ~/Desktop/performance> java-introcs Ramanujan 1729 true ~/Desktop/performance> java-introcs Ramanujan 3458 false ~/Desktop/performance> java-introcs Ramanujan 4104 true ~/Desktop/performance> java-introcs Ramanujan 216125 true ~/Desktop/performance> java-introcs Ramanujan 9223278330318728221 true 

    Your program should take time proportional to n1/3n1/3 in the worst case. It should be fast enough to process any 64-bit long integer in a fraction of a second.


image text in transcribed
2. Ramanujan numbers. When the English mathematician G. H. Hardy came to visit the Indian mathematician Srinivasa Ramanujan 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, Handy! It is a very interesting number; it is the smallest number expressible as the sum of two cubes in two different ways. An integer n is a Ramanujan number if can be expressed as the sum of two positive cubes in two different ways. That is, there are four distinct positive integers a,b,c, and d such that n=a3+b3=c3+d3. For example 1729=13+123=93+103 Write a program Ramanujan . java that takes a long integer command-line argument n and prints true if it is a Ramanujan number, and false otherwise. To do so, organize your program according to the following public API: public class Ramanujan \{ public static boolean is ramanujan(long n) // Takes a long integer command-1ine arguhents in and prints true if public static void main (String[l args) f is a Ramanan number, and false otherwise. Here are a few sample executions: //Desktop/performances java-introcs Ramanujan 1729 true //Desktop/performance> java-introcs Ramanujan 3458 false //Desktop/performances java-introcs Ramanujan 4104 true //Desktop/performance> java-introcs Ramanujan 216125 true /Desktop/performance> java-introcs Ramanujan 9223278330318728221 true Your program should take time proportional to n1/3 in the worst case. It should be fast enough to process any 64-bit long integer in a fraction of a second

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions