Loops – Arithmetic – Problem #21
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Difficulty: Hard
Problem Statement
A Ramanujan number is a positive integer that is expressible as the sum of two cubes in two different ways. Write a program that takes an integer n as input and prints all integers less than or equal to n that can be expressed as the sum of two cubes in two different ways, i.e., find distinct positive integers a, b, c, and d such that a3 + b3 = c3 + d3 <= n. Use four nested for loops. The smallest Ramanujan number is 1729, since 103 + 93 = 123 + 13 = 1729. (Please read the 3's as cubes)