Skip to content

Commit 09febac

Browse files
committed
solved JavaCore task lvl 10 2025
1 parent f01c6e0 commit 09febac

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

  • JavaRushTasks/2.JavaCore/src/com/javarush/task/task20/task2025

JavaRushTasks/2.JavaCore/src/com/javarush/task/task20/task2025/Solution.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,32 @@
44

55
/*
66
Алгоритмы-числа
7+
Поиск самовлюблённых чисел или чисел Армстронга
8+
@see https://github.com/shamily/ArmstrongNumbers
79
*/
810
public class Solution {
911
public static long[] getNumbers(long N) {
1012
long[] result = null;
11-
long[] armstrNum = {
12-
1, 2, 3, 4, 5, 6, 7, 8, 9,
13-
153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727, 93084,
14-
548834, 1741725, 4210818, 9800817, 9926315, 24678050, 24678051,
15-
88593477, 146511208, 472335975, 534494836, 912985153, 4679307774L
13+
long[] armstrongNum = {
14+
1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474,
15+
54748, 92727, 93084, 548834, 1741725, 4210818, 9800817, 9926315,
16+
24678050, 24678051, 88593477, 146511208, 472335975, 534494836,
17+
912985153, 4679307774L, 32164049650L, 32164049651L, 40028394225L,
18+
42678290603L, 44708635679L, 49388550606L, 82693916578L,
19+
94204591914L, 28116440335967L, 4338281769391370L,
20+
4338281769391371L, 21897142587612075L, 35641594208964132L,
21+
35875699062250035L, 1517841543307505039L, 3289582984443187032L,
22+
4498128791164624869L, 4929273885928088826L
1623
};
1724
int idx = 0;
18-
while (armstrNum[idx] < N) idx++;
19-
if (idx > 0) {
20-
result = new long[idx];
21-
for (int i = 0; i < result.length; i++)
22-
result[i] = armstrNum[i];
23-
}
25+
while (idx < armstrongNum.length && armstrongNum[idx] < N)
26+
idx++;
27+
result = new long[idx];
28+
System.arraycopy(armstrongNum, 0, result, 0, idx);
2429
return result;
2530
}
2631

2732
public static void main(String[] args) {
28-
System.out.println(Arrays.toString(getNumbers(8208)));
33+
//System.out.println(Arrays.toString(getNumbers(1)));
2934
}
3035
}

0 commit comments

Comments
 (0)