Source code for submission s769

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. package fl;
  6.  
  7. //import java.util.HashSet;
  8. import java.util.ArrayList;
  9. import java.util.HashSet;
  10. import java.util.Scanner;
  11. import java.util.TreeSet;
  12.  
  13. /**
  14.  *
  15.  * @author drevenak3
  16.  */
  17. public class FL {
  18.  
  19. /**
  20.   * @param args the command line arguments
  21.   */
  22. public static void main(String[] args) {
  23. // TODO code application logic here
  24. Scanner vst=new Scanner(System.in);
  25. int N,Y;
  26. while(vst.hasNext()){
  27. HashSet<Integer> pairs=new HashSet<Integer>();
  28. String ratio = vst.next();
  29. N=Integer.parseInt(ratio.substring(2, ratio.length()));
  30. if(N==1){
  31. System.out.println(1);
  32. continue;
  33. }
  34. int count=0;
  35. //long max=((N+1)*N)/2+1;
  36. int max=N*2;
  37. for(int y,x=N+1;x<=max;++x){
  38. if((N*x)%(x-N)==0){
  39. y=(N*x)/(x-N);
  40. //System.out.print("{"+x+","+y+"};");
  41. if(!pairs.contains(x)){
  42. pairs.add(x);
  43. pairs.add(y);
  44. ++count;
  45. }
  46. }
  47. }
  48. System.out.println(count);
  49. }
  50. vst.close();
  51. }
  52. }
  53.  

Diff to submission s726

FL.java

--- c5.s726.cteam083.fl.java.0.FL.java
+++ c5.s769.cteam083.fl.java.0.FL.java
@@ -5,6 +5,9 @@
 package fl;
 
+//import java.util.HashSet;
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.Scanner;
+import java.util.TreeSet;
 
 /**
@@ -22,5 +25,5 @@
         int N,Y;
         while(vst.hasNext()){
-            HashSet<Long> pairs=new HashSet<Long>();
+            HashSet<Integer> pairs=new HashSet<Integer>();
             String ratio = vst.next();
             N=Integer.parseInt(ratio.substring(2, ratio.length()));
@@ -30,8 +33,10 @@
             }
             int count=0;
-            long max=((N+1)*N)/2+1;
-            for(long y,x=N+1;x<=max;++x){
+            //long max=((N+1)*N)/2+1;
+            int max=N*2;
+            for(int y,x=N+1;x<=max;++x){
                 if((N*x)%(x-N)==0){
                     y=(N*x)/(x-N);
+                    //System.out.print("{"+x+","+y+"};");
                     if(!pairs.contains(x)){
                         pairs.add(x);