Source code for submission s611

Go to diff to previous submission

Fl.java

  1.  
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5.  
  6. public class Fl {
  7.  
  8. public static void main(String[] args) throws FileNotFoundException {
  9.  
  10. Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
  11. //Scanner sc = new Scanner(new BufferedReader(new FileReader(new File("in.txt"))));
  12.  
  13. int i = 1;
  14.  
  15. while (sc.hasNextLine()) {
  16.  
  17. int n = Integer.parseInt(sc.next().substring(2));
  18. sc.nextLine();
  19.  
  20.  
  21. if (n == 1) {
  22. System.out.println("1");
  23. continue;
  24. }
  25.  
  26.  
  27.  
  28. int x = n + 1;
  29.  
  30. double y = (n*x)/ (double) (x-n);
  31.  
  32. int sum = 0;
  33.  
  34. List<Integer> list = new ArrayList<Integer>();
  35.  
  36.  
  37. for (; ; x++) { // y < n +1
  38. y = (n*x)/ (double) (x-n);
  39.  
  40. if (y <= n+1) break;
  41.  
  42. if ((int) y - y == 0) {
  43. if (list.contains((int) y)) break;
  44.  
  45. sum++;
  46. list.add(x);
  47. }
  48. }
  49.  
  50. System.out.println(sum);
  51.  
  52.  
  53. }
  54. }
  55.  
  56. }
  57.  

Diff to submission s572

Fl.java

--- c5.s572.cteam054.fl.java.0.Fl.java
+++ c5.s611.cteam054.fl.java.0.Fl.java
@@ -1,5 +1,4 @@
 
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
+import java.io.*;
 import java.util.*;
 
@@ -7,13 +6,16 @@
 public class Fl {
         
-        public static void main(String[] args) {
-                System.out.println();
+        public static void main(String[] args) throws FileNotFoundException {
+                                
+                Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
+                //Scanner sc = new Scanner(new BufferedReader(new FileReader(new File("in.txt"))));
                 
+                int i = 1;
                 
-                Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
+                while (sc.hasNextLine()) {
                 
-                while (sc.hasNextLine()) {                      
                         int n = Integer.parseInt(sc.next().substring(2));                       
-                        sc.nextLine();   
+                        sc.nextLine();
+                
                         
                         if (n == 1) {
@@ -22,4 +24,6 @@
                         }
                         
+                        
+                        
                         int x = n + 1;
                         
@@ -28,14 +32,15 @@
                         int sum = 0;                                    
                         
-                        List<Integer> list = new ArrayList<Integer>();
-                        
+                        List<Integer> list = new ArrayList<Integer>();  
                         
                         
                         for (; ; x++) {                 // y < n +1 
                                 y = (n*x)/ (double) (x-n);
-                                                        
+                                        
+                                if (y <= n+1) break;
                                 
                                 if ((int) y - y == 0) {
                                         if (list.contains((int) y)) break;
+                                        
                                         sum++;
                                         list.add(x);
@@ -45,4 +50,5 @@
                         System.out.println(sum);
                         
+                        
                 }               
         }