fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. double abs(double argument) {
  5. return argument >= 0 ? argument : -argument;
  6. }
  7.  
  8. int ceil(double argument) {
  9. int result = (int) argument;
  10. if((double) result != argument && argument > 0) {
  11. result++;
  12. } else if((double) result == argument && argument < 0) {
  13. result++;
  14. }
  15. return result;
  16. }
  17.  
  18. int determineOrderOfPolynomial(double argument, double accuracy) {
  19. int order = 1;
  20. double a = 2 * argument;
  21. while(abs(a) >= accuracy) {
  22. order++;
  23. a *= 2 * argument / (order + 1);
  24. }
  25. return order;
  26. }
  27.  
  28. double function(double argument, double accuracy) {
  29. int order = determineOrderOfPolynomial(argument, accuracy);
  30. double summand = 2;
  31. double sum = summand;
  32. for(int k = 2; k <= ceil(order / 2.0); k++) {
  33. summand *= -4 * argument * argument / ((2 * k - 2) * (2 * k - 1));
  34. sum += summand;
  35. }
  36. return sum;
  37. }
  38.  
  39. int main() {
  40. double argument, accuracy;
  41. cin >> argument >> accuracy;
  42. if(argument == 0) {
  43. cout << "empty set";
  44. } else {
  45. cout << function(argument, accuracy);
  46. }
  47. cout << endl;
  48. return 0;
  49. }
Time limit exceeded #stdin #stdout 5s 3460KB
stdin
-1 0.00001
stdout
Standard output is empty