Source code for submission s998

Fl.java

  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. class Fl {
  6. private static BufferedReader in = new BufferedReader(
  7.  
  8. static int max(int x, int y) {
  9. return x > y ? x : y;
  10. }
  11.  
  12. static int nsn(int a, int b) {
  13. int res = max(a, b);
  14.  
  15. while (res <= a * b) {
  16. if ((res % a == 0) && (res % b == 0)) {
  17. break;
  18. }
  19.  
  20. res++;
  21. }
  22.  
  23. return res;
  24. }
  25.  
  26. static int lotion(int n) {
  27. int x, y, a, b, c, res, nsn;
  28. x = n + 1;
  29. res = 0;
  30.  
  31. while (x <= 2 * n) {
  32. nsn = nsn(n, x);
  33. //System.out.println(nsn);
  34. a = nsn / n;
  35. b = nsn / x;
  36. c = a - b;
  37.  
  38. if ((nsn % b == 0) && (nsn % c == 0)) {
  39. y = nsn / c;
  40. //System.out.println(String.format("%d: {%d, %d}", n, x, y));
  41. res++;
  42. }
  43.  
  44. x++;
  45. }
  46.  
  47. return res;
  48. }
  49.  
  50. /**
  51. * @param args
  52. */
  53. public static void main(String[] args) throws IOException {
  54. String line;
  55.  
  56. while ((line = in.readLine()) != null && line.length() > 2) {
  57. int n = Integer.parseInt(line.substring(2));
  58.  
  59. System.out.println(lotion(n));
  60. }
  61.  
  62. }
  63.  
  64. }
  65.