Source code for submission s1014

Go to diff to previous submission

Fl.java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. import java.util.Scanner;
  7.  
  8. /**
  9.  *
  10.  * @author cteam017
  11.  */
  12. public class Fl {
  13.  
  14. /**
  15.   * @param args the command line arguments
  16.   */
  17. public static void main(String[] args) {
  18. Scanner sc = new Scanner(System.in);
  19.  
  20. while (sc.hasNext()) {
  21. int counter = 0;
  22.  
  23. String line = sc.next();
  24. line = line.substring(line.indexOf("/") + 1, line.length());
  25. int n = Integer.valueOf(line);
  26.  
  27. int jmen = n * (n + 1);
  28.  
  29. for (int i = 1;; i++) {
  30. if (jmen % i == 0) {
  31. counter++;
  32. }
  33.  
  34. if (((double) i) / jmen > 1.0 / (n * 2)) {
  35. break;
  36. }
  37. jmen += n;
  38. }
  39.  
  40. System.out.println(counter);
  41. }
  42. }
  43. }
  44.  

Diff to submission s786

Fl.java

--- c5.s786.cteam017.fl.java.0.Fl.java
+++ c5.s1014.cteam017.fl.java.0.Fl.java
@@ -1,6 +1,18 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
 import java.util.Scanner;
 
+/**
+ *
+ * @author cteam017
+ */
 public class Fl {
 
+    /**
+     * @param args the command line arguments
+     */
     public static void main(String[] args) {
         Scanner sc = new Scanner(System.in);
@@ -13,59 +24,20 @@
             line = line.substring(line.indexOf("/") + 1, line.length());
             int n = Integer.valueOf(line);
+            
+            int jmen = n * (n + 1);
 
-//        System.out.println(lcm(sc.nextInt(), sc.nextInt()));
-
-            for (int i = n + 1;; i++) {
-//            System.out.println("1/"+n + "  &  1/"+i);
-                int lcm = getLcm(n, i);
-//            System.out.println("  lcm = "+lcm);
-                int nCitatel = lcm / n;
-                int iCitatel = lcm / i;
-
-//            System.out.println("  --> "+nCitatel+"/"+lcm+"  &  "+iCitatel+"/"+lcm);
-
-                int resCitatel = nCitatel - iCitatel;
-
-                int vysl = -1;
-                if (lcm % resCitatel == 0) {
-                    vysl = lcm / resCitatel;
-                }
-
-                if (vysl != -1) {
+            for (int i = 1;; i++) {
+                if (jmen % i == 0) {
                     counter++;
-//                System.out.println("  !Counter++");
                 }
-//            System.out.println("\n\n");
 
-                if (lcm == i) {
+                if (((double) i) / jmen > 1.0 / (n * 2)) {
                     break;
                 }
+                jmen += n;
             }
 
             System.out.println(counter);
         }
-
-    }
-
-    public static int getLcm(int a, int b) {
-        int starta = a;
-        int startb = b;
-
-        if (b > a) {
-            int tmp = a;
-            a = b;
-            b = tmp;
-        }
-
-//        System.out.println("--------------");
-//        System.out.println("  lcm("+a+", "+b+")");
-//        System.out.println("--------------");
-        while (a % b != 0) {
-            int rest = a % b;
-            a = b;
-            b = rest;
-        }
-
-        return starta * startb / b;
     }
 }