Source code for submission s1016

Go to diff to previous submission

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 = x * n;
  33.  
  34. //System.out.println(nsn);
  35. a = nsn / n;
  36. b = nsn / x;
  37. c = a - b;
  38.  
  39. if ((nsn % b == 0) && (nsn % c == 0)) {
  40. y = nsn / c;
  41. //System.out.println(String.format("%d: {%d, %d}", n, x, y));
  42. res++;
  43. }
  44.  
  45. x++;
  46. }
  47.  
  48. return res;
  49. }
  50.  
  51. /**
  52. * @param args
  53. */
  54. public static void main(String[] args) throws IOException {
  55. String line;
  56.  
  57. while ((line = in.readLine()) != null && line.length() > 2) {
  58. int n = Integer.parseInt(line.substring(2));
  59.  
  60. System.out.println(lotion(n));
  61. }
  62.  
  63. }
  64.  
  65. }
  66.  

Diff to submission s998

Fl.java

--- c5.s998.cteam060.fl.java.0.Fl.java
+++ c5.s1016.cteam060.fl.java.0.Fl.java
@@ -31,5 +31,6 @@
 
                 while (x <= 2 * n) {
-                        nsn = nsn(n, x);
+                        nsn = x * n;
+                        
                         //System.out.println(nsn);
                         a = nsn / n;