Source code for submission s648

Go to diff to previous submission

f1.cpp

  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <cstdio>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. int main ()
  10. {
  11. unsigned long n, x, y, pocet;
  12. n = x = y = pocet = 0;
  13. string input;
  14. vector<unsigned long> pouzite;
  15. bool nasel = false;
  16.  
  17. while (cin)
  18. {
  19. cin >> input;
  20. n = atoi(input.c_str()+2);
  21. x = n+1;
  22. if (n == 0)
  23. {
  24. cout << 0 << "\n";
  25. continue;
  26. }
  27. if (n == 1)
  28. {
  29. cout << 1 << "\n";
  30. continue;
  31. }
  32. while (float((x*n))/(x-n) > n+1)
  33. {
  34. if((x*n)%(x-n)==0)
  35. {
  36. y = x*n/(x-n);
  37. //if (y < x) break;
  38. nasel = false;
  39. for (vector<unsigned long>::iterator i = pouzite.begin(); i != pouzite.end(); i++)
  40. {
  41. if ((*i) == y)
  42. {
  43. nasel = true;
  44. break;
  45. }
  46. }
  47. if (!nasel)
  48. {
  49. pocet++;
  50. pouzite.push_back(x);
  51. }
  52. //if (y == x) break;
  53. }
  54. x++;
  55. }
  56. y = 0;
  57. x = 0;
  58. cout << pocet << "\n";
  59. pocet = 0;
  60. }
  61.  
  62. return 0;
  63. }
  64.  

Diff to submission s530

f1.cpp

--- c5.s530.cteam016.fl.cpp.0.f1.cpp
+++ c5.s648.cteam016.fl.cpp.0.f1.cpp
@@ -3,4 +3,5 @@
 #include <cstdlib>
 #include <cstdio>
+#include <vector>
 
 using namespace std;
@@ -11,4 +12,6 @@
  n = x = y = pocet = 0;
  string input;
+ vector<unsigned long> pouzite;
+ bool nasel = false;
 
  while (cin)
@@ -17,4 +20,9 @@
   n = atoi(input.c_str()+2);
   x = n+1;
+  if (n == 0)
+  {
+   cout << 0 << "\n";
+   continue;
+  }
   if (n == 1)
   {
@@ -22,14 +30,25 @@
    continue;
   }
-  while (true)
+  while (float((x*n))/(x-n) > n+1)
   {
    if((x*n)%(x-n)==0)
    {
     y = x*n/(x-n);
-    if (y < x) break;
-
-    pocet++;
-
-    if (y == x) break;
+    //if (y < x) break;
+    nasel = false;
+    for (vector<unsigned long>::iterator i = pouzite.begin(); i != pouzite.end(); i++)
+    {
+     if ((*i) == y)
+     {
+      nasel = true;
+      break;
+     }
+    }
+    if (!nasel)
+    {
+     pocet++;
+     pouzite.push_back(x);
+    }
+    //if (y == x) break;
    }
    x++;