Source code for submission s720

Go to diff to previous submission

fl.java

  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.ArrayList;
  5. import java.util.Arrays;
  6. import java.util.HashSet;
  7. import java.util.List;
  8. import java.util.Set;
  9. import java.util.regex.Pattern;
  10.  
  11. public class fl {
  12.  
  13. public static void main(String[] args) throws IOException {
  14. int[] predvypocet= new int[10001];
  15. for (long n = 0; n < 10001; n++) {
  16. int count = 0;
  17. Set<Integer> s=new HashSet<Integer>();
  18. for (long x = n + 1; x < 20001; x++) {
  19. if (x - n != 0) {
  20. int ymod = (int) ((n * x) % (x - n));
  21. if (ymod == 0) {
  22. int y = (int) ((n * x) / (x - n));
  23. if (y != 0) {
  24. if (!s.contains(y)) {
  25. s.add((int) x);
  26. s.add(y);
  27. count++;
  28. // System.out
  29. // .println("n " + n + " x: " + x + " y" + y);
  30. }
  31.  
  32. }
  33. }
  34.  
  35. }
  36. }
  37. predvypocet[(int) n]=count;
  38.  
  39. }
  40.  
  41. Pattern p = Pattern.compile("/");
  42. String line;
  43. while ((line = buf.readLine()) != null) {
  44. String[] s = p.split(line);
  45. int n = Integer.parseInt(s[1]);
  46. System.out.println(predvypocet[n]);
  47. }
  48. }
  49.  
  50. }
  51.  

Diff to submission s691

fl.java

--- c5.s691.cteam096.fl.java.0.fl.java
+++ c5.s720.cteam096.fl.java.0.fl.java
@@ -13,49 +12,8 @@
 
         public static void main(String[] args) throws IOException {
-                
-                
-                
-                
-//              int[] res = new int[10002];
-//              int[] res2 = new int[10002];
-//              long o = 10000000;
-//              for(long x=1; x<100000; x++){
-//                      for(long y=x; y<o; y+=x){
-//                              if(x*y % (x+y)==0){
-//                                      int n = ((int)(x*y/(x+y)));
-//                                      if(n<res.length)
-//                                      res[n]++;
-//                                      if(n==5000)
-//                                              System.out.println(x + " " + y + " " + x*y/(x+y));
-//                              }
-//                      }
-//              }
-//              System.out.println(Arraresultys.toString(res));
-//              for(int n=5000; n<5001; n++){
-//                      for (int i = 1; i <= n; i++) {
-//                              if(n % i == 0){
-//                                      res2[n]++;
-//                                      System.out.println(i);
-//                              }
-//                      }
-//              }
-//              System.out.println(Arrays.toString(res2));
-//              for(int i=0; i< 1000; i++){
-//                      if (res[i] != res2[i]){
-//                              System.out.println(i);
-//                              break;
-//                      }
-//              }
-//              System.out.println(res[5000]);          
-//              System.out.println(res2[5000]);
-                
-                BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
-                Pattern p = Pattern.compile("/");
-                String line;
-                while ((line = buf.readLine()) != null) {
-                        String[] s = p.split(line);
-                        int n = Integer.parseInt(s[1]);
+                int[] predvypocet= new int[10001];
+                for (long n = 0; n < 10001; n++) {
                         int count = 0;
-                        Set<Integer> set=new HashSet<Integer>();
+                        Set<Integer> s=new HashSet<Integer>();
                         for (long x = n + 1; x < 20001; x++) {
                                 if (x - n != 0) {
@@ -64,7 +22,7 @@
                                                 int y = (int) ((n * x) / (x - n));
                                                 if (y != 0) {
-                                                        if (!set.contains(y)) {
-                                                                set.add((int) x);                                                       
-                                                                set.add(y);
+                                                        if (!s.contains(y)) {
+                                                                s.add((int) x);                                                 
+                                                                s.add(y);
                                                                 count++;
 //                                                              System.out
@@ -77,5 +35,16 @@
                                 }
                         }
-                        System.out.println(count);
+                        predvypocet[(int) n]=count;
+ 
+                }
+
+                BufferedReader buf = new BufferedReader(
+                                new InputStreamReader(System.in));
+                Pattern p = Pattern.compile("/");
+                String line;
+                while ((line = buf.readLine()) != null) {
+                        String[] s = p.split(line);
+                        int n = Integer.parseInt(s[1]);
+                        System.out.println(predvypocet[n]);
                 }
         }