Всем здравствовать. Намекните, пожалуйста, что нужно переделать, как ускорить программу, Спасибо всем, кому будет не лень посмотреть)
package com.javarush.task.task20.task2025;
import com.sun.security.jgss.GSSUtil;
import java.util.*;
/*
Алгоритмы-числа
*/
public class Solution {
public static long[] getNumbers(long N) {
long[] result = null;
genPows(19);
SortedSet<Long> results = new TreeSet<>();
long x = 1;
do{
boolean itsNormNum = true;
long num = x;
do{
int x2 = (int)num % 10;
num /= 10;
int x1 = (int)num % 10;
if((x2 < x1)) itsNormNum = false;
}
while(num != 0);
if(itsNormNum ){
long z = x;
for(int q = 0; q<4; q++){
long sum = getPowsSum(z);
if(checkForArm(sum) && !results.contains(sum)){
results.add(sum);
}
z *= 10;
}
}
x += 1;
}while(x < N);
result = new long[results.size()];
Iterator<Long> itr = results.iterator();
int count = 0;
while(itr.hasNext()){
result[count] = itr.next();
count++;
}
for(int coun = 0;coun <result.length; coun++){
System.out.println(result[coun]);
}
return result;
}
private static long[][] pows;
private static void genPows(int N){
if(N>20) throw new IllegalArgumentException();
pows = new long[10][N + 1];
for(int i = 0; i<pows.length; i++){
long p = 1;
for(int j = 0;j < pows[i].length; j++){
pows[i][j] = p;
p *= i;
}
}
}
private static boolean checkForArm(long i){
long powsSum = 0;
long x = i;
int N = (int)Math.log10(x) + 1;
do{
int mod = (int)x % 10;
if(mod<0) mod *= -1;
powsSum += pows[mod][N];
x /= 10;
}while(x != 0);
return powsSum == i;
}
private static long getPowsSum(long i){
long powsSum = 0;
long x = i;
int N = (int)Math.log10(x) + 1;
do{
int mod = (int)x % 10;
if(mod <0){
mod *= -1;
}
long p = pows[mod][N];
powsSum += p;
x /= 10;
}while(x != 0);
return powsSum;
}
public static void main(String[] args) {
long start = System.currentTimeMillis();
getNumbers(100000000);
long finish = System.currentTimeMillis();
System.out.println("Time consumed: " + (finish - start) + " ms");
}
}