momo3141

Least Majority Multiple

Dec 23rd, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.84 KB | Source Code | 0 0
  1.  et input = [
  2. '30',
  3. '42',
  4. '70',
  5. '35',
  6. '90'
  7. ];
  8. let print = this.print || console.log;
  9. let gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
  10. //Code
  11. let a = +gets();
  12. let b = +gets();
  13. let c = +gets();
  14. let d = +gets();
  15. let e = +gets();
  16.  
  17. function gcd(num1, num2){
  18.   while(num1 !== num2){
  19.     if(num1 > num2){
  20.       num1 = num1 - num2;
  21.     } else {
  22.       num2 = num2 - num1;
  23.     }
  24.   }
  25.  return(num2);
  26. }
  27.  
  28. function lcm(n1,n2){
  29.   return n1*n2/gcd(n1, n2);
  30. }
  31.  
  32. console.log(Math.min((lcm(a,lcm(b,c))),
  33.                 (lcm(a,lcm(b,d))),
  34.                (lcm(a,lcm(b,e))),
  35.                (lcm(b,lcm(c,d))),
  36.                (lcm(b,lcm(c,e))),
  37.                (lcm(c,lcm(d,e))),
  38.                (lcm(c,lcm(d,a))),
  39.                (lcm(a,lcm(c,e))),
  40.                (lcm(b,lcm(d,e))),
  41.                (lcm(a,lcm(d,e)))));
  42.  
Advertisement
Add Comment
Please, Sign In to add comment