Уже несколько дней бьюсь над этой задачей и просто не могу понять где он нашел ошибку.
package com.javarush.task.task20.task2025;
import java.util.*;
/*
Алгоритмы-числа
*/
public class Solution {
public static long[][] matrix;
public static long SSS;
public static long[] getNumbers(long N) {
if (N <= 1) {
return new long[0];
}
long[] arrofnumbers;
SSS = N;
List<Long> temp = new ArrayList<>();
String nnnnSize = String.valueOf(N);
int S = nnnnSize.length();
matrix = matrix(S);
arrofnumbers = new long[S];
Arrays.fill(arrofnumbers, 10);
int arrcount = 0;
while (decrementArray(arrofnumbers)) {
int checks = 0;
while (checks == 0) {
long result = 0;
for (int i = 0; i <= arrcount; i++) {
result += matrix[arrcount][(int) arrofnumbers[i]];
}
if (result == newcheck(result)) {
if (result != 0) {
if (result <= SSS & !temp.contains(result)) {
temp.add(result);
}
}
}
if (arrofnumbers[0] == 0) {
checks = 1;
}
if (arrofnumbers[0] != 0) arrofnumbers[0]--;
if (arrofnumbers[0] == 0) {
checks = 1;
result = 0;
for (int i = 0; i <= arrcount; i++) {
result += matrix[arrcount][(int) arrofnumbers[i]];
}
if (result == newcheck(result)) {
if (result != 0) {
if (result <= SSS & !temp.contains(result)) {
temp.add(result);
}
}
}
}
}
if (arrofnumbers[arrcount] == 0) {
arrcount++;
}
}
return endgame(temp);
}
public static long[] endgame (List<Long> end) {
List<Long> forsort = new ArrayList<>();
for (Long ss : end) {
if (ss < SSS) forsort.add(ss);
}
long[] retthis = new long[forsort.size()];
for (int i = 0; i < retthis.length; i++) {
retthis[i] = forsort.get(i);
}
Arrays.sort(retthis);
return retthis;
}
private static boolean decrementArray(long[] arrofnumbers) {
int index = 0;
while (index < arrofnumbers.length && arrofnumbers[index] == 0) {
index++;
}
if (index + 1 == arrofnumbers.length && arrofnumbers[index] == 1) {
return false;
}
Arrays.fill(arrofnumbers, 0, index + 1, arrofnumbers[index] - 1);
return true;
}
public static long newcheck(long temp) {
int SRRR = String.valueOf(temp).length();
long lel = temp;
long result = 0;
if (result > temp) return result;
long multi;
while (lel != 0) {
multi = lel%10;
if (multi == 1) {
result += 1;
lel = lel/10;
continue;
}
if (multi == 0) {
lel = lel/10;
continue;
}
result += matrix[SRRR-1][(int)multi];
lel = lel/10;
}
return result;
}
public static long[][] matrix (int A) {
long[][] temp = new long[A+1][10];
for (int i = 0; i < 10; i++) {
temp[0][i] = i;
}
for (int i = 1; i < 10; i++) {
long getNumb = temp[0][i];
for (int j = 1; j < A+1; j++) {
temp[j][i] = temp[j-1][i]*getNumb;
}
}
return temp;
}
public static void main(String[] args) {
long a = System.currentTimeMillis();
System.out.println(Arrays.toString(getNumbers(1000)));
System.out.println(Arrays.toString(getNumbers(154)));
long b = System.currentTimeMillis();
System.out.println("memory " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (8 * 1024));
System.out.println("time = " + (b - a) / 1000);
a = System.currentTimeMillis();
System.out.println(Arrays.toString(getNumbers(1000000)));
b = System.currentTimeMillis();
System.out.println("memory " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (8 * 1024));
System.out.println("time = " + (b - a) / 1000);
a = System.currentTimeMillis();
System.out.println(Arrays.toString(getNumbers(Long.MAX_VALUE)));
b = System.currentTimeMillis();
System.out.println("memory " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (8 * 1024));
System.out.println("time = " + (b - a) / 1000);
a = System.currentTimeMillis();
System.out.println(Arrays.toString(getNumbers(999999999999999999L)));
b = System.currentTimeMillis();
System.out.println("memory " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (8 * 1024));
System.out.println("time = " + (b - a) / 1000);
}
}
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407]
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 153]
// memory 368
// time = 0
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727, 93084, 548834]
// memory 512
// time = 0
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727, 93084, 548834, 1741725, 4210818, 9800817, 9926315, 24678050, 24678051, 88593477, 146511208, 472335975, 534494836, 912985153, 4679307774, 32164049650, 32164049651, 40028394225, 42678290603, 44708635679, 49388550606, 82693916578, 94204591914, 28116440335967, 4338281769391370, 4338281769391371, 21897142587612075, 35641594208964132, 35875699062250035, 1517841543307505039, 3289582984443187032, 4498128791164624869, 4929273885928088826]
// memory 8244
// time = 3
// [1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727, 93084, 548834, 1741725, 4210818, 9800817, 9926315, 24678050, 24678051, 88593477, 146511208, 472335975, 534494836, 912985153, 4679307774, 32164049650, 32164049651, 40028394225, 42678290603, 44708635679, 49388550606, 82693916578, 94204591914, 28116440335967, 4338281769391370, 4338281769391371, 21897142587612075, 35641594208964132, 35875699062250035]
// memory 12337
// time = 1