Project Euler > Problem 62 > Cubic permutations (Java Solution)

Problem:

The cube, 41063625 (3453), can be permuted to produce two other cubes: 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the smallest cube which has exactly three permutations of its digits which are also cube.

Find the smallest cube for which exactly five permutations of its digits are cube.


Solution:

76576500

Code:
The solution may include methods that will be found here: Library.java .

public interface EulerSolution{

public String run();

}
/* 
* Solution to Project Euler problem 12
* By Nayuki Minase
*
* http://nayuki.eigenstate.org/page/project-euler-solutions
* https://github.com/nayuki/Project-Euler-solutions
*/


public final class p012 implements EulerSolution {

public static void main(String[] args) {
System.out.println(new p012().run());
}


public String run() {
int num = 0;
for (int i = 1; ; i++) {
num += i; // num is triangle number i
if (countDivisors(num) > 500)
return Integer.toString(num);
}
}


private static int countDivisors(int n) {
int count = 0;
int end = Library.sqrt(n);
for (int i = 1; i < end; i++) {
if (n % i == 0)
count += 2;
}
if (end * end == n) // Perfect square
count++;
return count;
}

}


No comments :

Post a Comment

Follow Me

If you like our content, feel free to follow me to stay updated.

Subscribe

Enter your email address:

We hate spam as much as you do.

Upload Material

Got an exam, project, tutorial video, exercise, solutions, unsolved problem, question, solution manual? We are open to any coding material. Why not upload?

Upload

Copyright © 2012 - 2014 Java Problems  --  About  --  Attribution  --  Privacy Policy  --  Terms of Use  --  Contact