-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEasiestProblem.java
46 lines (37 loc) · 1.11 KB
/
EasiestProblem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
Problem: https://open.kattis.com/problems/easiest
Author: Adrian Reithaug
Submitted: May 31st, 2017
Time: 0.17s / 1.00s
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class EasiestProblem {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
int number = Integer.parseInt(reader.readLine());
if (number == 0) {
break;
}
int target = sumOfDigits(number);
int minimal = 11;
while (true) {
if (sumOfDigits(number * minimal) == target) {
System.out.println(minimal);
break;
}
minimal++;
}
}
}
public static int sumOfDigits(int number) {
int sum = 0;
char[] numbArr = Integer.toString(number).toCharArray();
for (char c : numbArr) {
sum += Character.getNumericValue(c);
}
return sum;
}
}