Find the first (Note that two related but different are specified sets For example: ago> I face the view of algorithm or Si snippet The problem should be. To print the N Ramanujan number below Java code is also better because it also has less time complexity because it has only one loop in it. n taxicab number by looking at a value
n First of all I want to find N taxicab number. A taxicab is a number that can be expressed in the form of the sum of two perfect cubes in more than one way.
1 ^ 3 + 12 ^ 3 = 1729 = 9 ^ 3 + 10 ^ 3
The first five of these are: IJKL number ---------------------------- ----- 1 12 9 10 1729 2 16 9 15 4104 2 24 18 20 13832 10 27 1924 20683 4 32 18 30 32832
import java.util. *; Public class solutionArmnujan {public static zero main []) Exceptions thrown {SolutionRamanujan s = new SolutionRamanujan (); Scanner scan = new scanner (System.in); Int n = scan.nextInt (); Int i = 0, k = 1; while (i & lt; N) {if (s.checkRamanujan (k)) {i = i + 1; System.out.println (I + "is the Ramanujan number" + K); } K ++; } Scan.close (); } // Check whether a number is Ramanujan number Public Boolean checkman (int a) {int count = 0; Int cbrt = (int) Math.cbrt (a); For the // I, the numbers below the number and the number of cube (int i = 1; i & lt; = cbrt; i ++) {int difference = a- (i * i * i); Int a1 = (int) Math.cbrt (difference); // Check if the difference is the correct cube (a1 == Math.cbrt (difference)) {count = count + 1; } If (that is present in 2 such joints (ie> 2) check that i.e. (a * a * a) + (b * b * b) = (c * c * c) + ( D * d * d) = number back true;}} description is false;}}
Comments
Post a Comment