Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class Main implements Runnable {
- private void solution() throws IOException {
- while (in.hasNext()) {
- int n = in.nextInt();
- if (n == 0) {
- break;
- }
- for (int p = 11; ; ++p) {
- if (f(n) == f(n * p)) {
- out.println(p);
- break;
- }
- }
- }
- }
- private int f(int n) {
- int res = 0;
- while (n != 0) {
- res += n % 10;
- n /= 10;
- }
- return res;
- }
- public void run() {
- try {
- solution();
- in.reader.close();
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- System.exit(1);
- }
- }
- public static void main(String[] args) {
- new Thread(null, new Main(), "", 1 << 28).start();
- }
- private class Scanner {
- BufferedReader reader;
- StringTokenizer tokenizer;
- public Scanner(Reader reader) {
- this.reader = new BufferedReader(reader);
- this.tokenizer = new StringTokenizer("");
- }
- public boolean hasNext() throws IOException {
- while (!tokenizer.hasMoreTokens()) {
- String line = reader.readLine();
- if (line == null) {
- return false;
- }
- tokenizer = new StringTokenizer(line);
- }
- return true;
- }
- public String next() throws IOException {
- hasNext();
- return tokenizer.nextToken();
- }
- public int nextInt() throws IOException {
- return Integer.parseInt(next());
- }
- }
- Scanner in = new Scanner(new InputStreamReader(System.in));
- PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement