Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. const input = ['17'];
  2. const print = this.print || console.log;
  3. const gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  4. let n = +gets();
  5. let bearLegs = 2;
  6. let humanLegs = 5;
  7. let chickenLegs = 7;
  8. let count = 0;
  9.  
  10. for (let bearLegsPair = 0; bearLegsPair <= Math.floor(n / bearLegs); bearLegsPair++) {
  11. for (let humanLegsPair = 0; humanLegsPair <= Math.floor(n / humanLegs); humanLegsPair++) {
  12. for (let chickenLegsPair = 0; chickenLegsPair <= Math.floor(n / chickenLegs); chickenLegsPair++) {
  13. let bear = bearLegs * bearLegsPair;
  14. let human = humanLegs * humanLegsPair;
  15. let chicken = chickenLegs * chickenLegsPair;
  16. let sum = bear + human + chicken;
  17. if (sum === n) {
  18. count++;
  19. }
  20. }
  21. }
  22. } print(count);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement