Source code for submission s662

Go to diff to previous submission

fl1.cpp

  1. // Fractional Lotion
  2. // VOGEL BROTHERS
  3.  
  4. #include <cstdlib>
  5. #include<cmath>
  6. #include <iostream>
  7. using namespace std;
  8.  
  9. int func (int n) {
  10. int x,twoN, yInt, count;
  11. bool * results = new bool[n];
  12. for (int i = 0; i < n; i++) {
  13. results[i] = false;
  14. }
  15. float yFloat;
  16. twoN = n*2;
  17. count = 0;
  18. // calculate solutions
  19. for (x = n+1; x <= twoN; x++) {
  20. int nx, xmn; // nx = n*x, xmn = x - n
  21. nx = n*x;
  22. xmn = x-n;
  23. yFloat = (float) nx / (float) xmn;
  24. if (abs(yFloat - (int) yFloat) < 0.00001) {
  25. if (results[xmn-1] != true) {
  26. results[xmn-1] = true;
  27. count ++;
  28. }
  29. }
  30. }
  31. delete[]results;
  32. return count;
  33. }
  34.  
  35.  
  36. int main () {
  37. char dummy, dummy2;
  38. char temp[10];
  39. int n;
  40.  
  41. while (cin.getline(temp, 10)) {
  42.  
  43. n = atoi(temp+2);
  44. // print result
  45. cout << func(n) << endl;
  46. }
  47.  
  48. return 0;
  49. }
  50.  
  51.  
  52.  

Diff to submission s658

fl1.cpp

--- c5.s658.cteam047.fl.cpp.0.fl1.cpp
+++ c5.s662.cteam047.fl.cpp.0.fl1.cpp
@@ -22,5 +22,5 @@
                 xmn = x-n;
                 yFloat = (float) nx / (float) xmn;
-                if (abs(yFloat - (int) yFloat) < 0.000000001) {
+                if (abs(yFloat - (int) yFloat) < 0.00001) {
                         if (results[xmn-1] != true) {
                                 results[xmn-1] = true;