Source code for submission s495

Main.java

  1.  
  2. import java.io.BufferedReader;
  3. import java.io.InputStreamReader;
  4. import java.util.StringTokenizer;
  5.  
  6. public class Main {
  7.  
  8. public static void main(String[] args) throws Exception {
  9. Main p = new Main();
  10. p.run();
  11. }
  12.  
  13. protected void run() throws Exception {
  14. while (input.ready()) {
  15. String line = nextLine();
  16. int jmenovatel = Integer.parseInt(line.substring(2));
  17. int dvojnasobek = jmenovatel * 2;
  18. int results = 1;
  19. for (int i = jmenovatel + 1; i < dvojnasobek; i++) {
  20. if (validate(i, jmenovatel)) {
  21. results++;
  22. }
  23. }
  24. System.out.println(results);
  25. }
  26. }
  27.  
  28. protected boolean validate(int x, int n) {
  29. int citatel = n * x;
  30. int jmenovatel = x - n;
  31. return citatel % jmenovatel == 0;
  32. }
  33.  
  34.  
  35.  
  36.  
  37. public String nextToken() throws Exception {
  38. while (!st.hasMoreTokens()) {
  39. st = new StringTokenizer(input.readLine());
  40. }
  41. return st.nextToken();
  42. }
  43.  
  44. public int nextInt() throws Exception {
  45. return Integer.parseInt(nextToken());
  46. }
  47.  
  48. public String nextLine() throws Exception {
  49. return input.readLine();
  50. }
  51.  
  52. }
  53.