Smallest Common Multiple

x = a * b

a 的倍数是 x

a的多少倍是x

a * n = x

例如 3的倍数 3、6、9...

31、32、3*3...

b 的倍数是 x

a 和 b 的倍数中有相等的数,叫公倍数,就是你有我也有的数

最小公倍数,就是大家都有的数中最小的那个

最小公倍数

https://www.shuxuele.com/least-common-multiple.html

被除数 / 除数= 商

function smallestCommons(arr) {
  //能被a、b 及其中间的所有正整数整除的那个数(被除数)
  // i % a~b === 0
  let smallNum= Math.min(arr[0], arr[1])
  let bigNum= Math.max(arr[0], arr[1])

  for(let i=1; true; i++) {//可怕的ture
    let isSmallestCommonMultiple = true
    for(let j=smallNum; j<=bigNum; j++){
      if(i%j !== 0)//有无法整除的情况,这个i就不是目标
        isSmallestCommonMultiple = false
    }
    if(isSmallestCommonMultiple)
      return i
  }
}
smallestCommons([1,5]);

测试数据:

smallestCommons([1, 5]) should return a number. smallestCommons([1, 5]) should return 60. smallestCommons([5, 1]) should return 60. smallestCommons([2, 10]) should return 2520. smallestCommons([1, 13]) should return 360360. smallestCommons([23, 18]) should return 6056820.