Problem specification: ProjectEuler.net Problem 30
I think a mis-understood specification led to a calculated "upper bound" of the loop. Luckily it yielded the correct answer, quickly.
Execution time: ~820ms (laptop)
CODE
package projecteuler;
/**
* Project euler problem 30 java solution
* @author Mike
*/
public class Problem_30 {
public static void main(String[] args){
new Problem_30();
}
public Problem_30(){
long start = System.currentTimeMillis();
int thetot = 0;
for(int i = 11; i < 295245;i++){
String val = String.valueOf(i);
int total = 0;
for(int j = 0; j < val.length(); j++){
total += Math.pow((val.charAt(j) - 48),5);
}
if(total == i){
thetot += i;
}
}
System.out.println(thetot);
long end = System.currentTimeMillis();
System.out.println(end - start + " ms");
}
}
Any suggestions and comments are welcome, please send me an email (see contacts).