Advertisement
CR7CR7

sum

Mar 21st, 2022
1,265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //"Calculate 1 + 1!/X + 2!/X^2 + … + N!/X^N");
  2. let input =['3','2'];
  3. let print = this.print || console.log;
  4. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  5. let n = Number(gets());
  6. let x = Number(gets());
  7. let result = 1;
  8. let ifac = 1;
  9. for (let i = 1; i <= n; i++)
  10. {
  11.     ifac = 1; //This line is very important
  12.     for (let j = i; j >= 1; j--)
  13.     {
  14.         ifac *= j;
  15.     }
  16.     result += ifac / Math.pow(x, i);
  17. }
  18. print(result.toFixed(5));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement