not sure if i can pass this one, because it keeps timing out.

package com.codegym.task.task20.task2025;
import java.util.*;
/*
Number algorithms
*/
public class Solution {
public static long[] getNumbers(long n) {
if (n <= 1) return new long[0];
check(n);
List<Long> list = new ArrayList<>();
for (int i = 1; i < n; ++i) {
int m = (int) (Math.floor(Math.log10(i)) + 1);
long x = i, sum = 0;
while (x > 0) {
long r = x % 10;
sum += Math.pow(r, m);
x /= 10;
}
if (sum == i) list.add(sum);
}
return Arrays.stream(list.toArray(new Long[0])).mapToLong(Long::longValue).toArray();
}
private static void check(long n) {
int m = (int) (Math.floor(Math.log10(n)) + 1);
if (m >= 21) throw new IllegalArgumentException();
}
public static void main(String[] args) {
long a = System.currentTimeMillis();
System.out.println(Arrays.toString(getNumbers(1000)));
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);
}
}

TONof cpu work. However if you cash those values in an array of ten indices: Long [0, 1, 128, 2187, 16384, 78125, 279936, 823543, 2097152, 4782969] (these are the digits 0-9 to the power of 7) Then instead of line 20 calling math.pow() you just need: sum += longArray[r]; You're code can gain over 90%+ increased efficiency by caching values instead of brute forcing.