public class Quersumme {
private final static int[] SUM = new int[] {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
18, 19, 20, 21, 22, 23, 24, 25, 26, 27
};
public static int quersumme(int zahl) {
int sum = 0;
while (zahl > 0) {
sum += SUM[zahl % 1000];
zahl /= 1000;
}
return sum;
}
public static void main(String ...args) {
System.out.println(quersumme(1234567));
}
}