Source code for submission s614

f1.cpp

  1. // Fractional Lotion
  2. // VOGEL BROTHERS
  3.  
  4. #include <cstdlib>
  5. #include <iostream>
  6. using namespace std;
  7.  
  8. int func (int n) {
  9. int x,twoN, yInt, count;
  10. bool * results = new bool[n];
  11. for (int i = 0; i < n; i++) {
  12. results[i] = false;
  13. }
  14. float yFloat;
  15. twoN = n*2;
  16. count = 0;
  17. // calculate solutions
  18. for (x = n+1; x <= twoN; x++) {
  19. int nx, xmn; // nx = n*x, xmn = x - n
  20. nx = n*x;
  21. xmn = x-n;
  22. yInt = nx / xmn;
  23. yFloat = (float) nx / (float) xmn;
  24. if ((float) yInt == yFloat) {
  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.