Advertisement
ErolKZ

Untitled

Sep 13th, 2021
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1.  
  2. let input = [
  3.  
  4. '4',
  5. '3'
  6.  
  7.  
  8. ];
  9.  
  10.  
  11.  
  12.  
  13. let print = this.print || console.log;
  14. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  15.  
  16.  
  17. // S = 1 + 1!/x + 2!/x2 + … + N!/xN.
  18.  
  19. // n! = n * (n-1)!
  20.  
  21. // n! = 1 if n = 0 or n = 1
  22.  
  23.  
  24. let N = Number(gets());
  25.  
  26. let x = Number(gets());
  27.  
  28. let factoriel = 1;
  29.  
  30. let sum = 0;
  31.  
  32. let sum2 = 0;
  33.  
  34.  
  35. for (let i = 1; i <= N; i++) {
  36.  
  37. factoriel *= i;
  38.  
  39. }
  40.  
  41.  
  42. console.log(factoriel);
  43.  
  44. sum += 1 + 1 / x + 2 / Math.pow(x, 2) + factoriel / Math.pow(x, N);
  45.  
  46.  
  47. print(sum.toFixed(5));
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement