Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Main implements Runnable {
  5. private void solution() throws IOException {
  6. while (in.hasNext()) {
  7. int n = in.nextInt();
  8. if (n == 0) {
  9. break;
  10. }
  11. for (int p = 11; ; ++p) {
  12. if (f(n) == f(n * p)) {
  13. out.println(p);
  14. break;
  15. }
  16. }
  17. }
  18. }
  19.  
  20. private int f(int n) {
  21. int res = 0;
  22. while (n != 0) {
  23. res += n % 10;
  24. n /= 10;
  25. }
  26. return res;
  27. }
  28.  
  29. public void run() {
  30. try {
  31. solution();
  32. in.reader.close();
  33. out.close();
  34. } catch (IOException e) {
  35. e.printStackTrace();
  36. System.exit(1);
  37. }
  38. }
  39.  
  40. public static void main(String[] args) {
  41. new Thread(null, new Main(), "", 1 << 28).start();
  42. }
  43.  
  44. private class Scanner {
  45. BufferedReader reader;
  46. StringTokenizer tokenizer;
  47.  
  48. public Scanner(Reader reader) {
  49. this.reader = new BufferedReader(reader);
  50. this.tokenizer = new StringTokenizer("");
  51. }
  52.  
  53. public boolean hasNext() throws IOException {
  54. while (!tokenizer.hasMoreTokens()) {
  55. String line = reader.readLine();
  56. if (line == null) {
  57. return false;
  58. }
  59. tokenizer = new StringTokenizer(line);
  60. }
  61. return true;
  62. }
  63.  
  64. public String next() throws IOException {
  65. hasNext();
  66. return tokenizer.nextToken();
  67. }
  68.  
  69. public int nextInt() throws IOException {
  70. return Integer.parseInt(next());
  71. }
  72. }
  73.  
  74. Scanner in = new Scanner(new InputStreamReader(System.in));
  75. PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement