Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

1.2 KiB
Raw Blame History

id, title, challengeType, videoUrl, dashedName
id title challengeType videoUrl dashedName
5900f3711000cf542c50fe84 问题5最小的倍数 5 problem-5-smallest-multiple

--description--

2520是可以除以1到10中的每个数字而没有任何余数的最小数字。从1到n所有数字均可被整除的最小正数是多少?

--hints--

smallestMult(5)应该返回60。

assert.strictEqual(smallestMult(5), 60);

smallestMult(7)应该返回420。

assert.strictEqual(smallestMult(7), 420);

smallestMult(10)应返回2520。

assert.strictEqual(smallestMult(10), 2520);

smallestMult(13)应返回360360。

assert.strictEqual(smallestMult(13), 360360);

smallestMult(20)应该返回232792560。

assert.strictEqual(smallestMult(20), 232792560);

--seed--

--seed-contents--

function smallestMult(n) {

  return true;
}

smallestMult(20);

--solutions--

function smallestMult(n){
  function gcd(a, b) {
    return b === 0 ? a : gcd(b, a%b); // Euclidean algorithm
  }

  function lcm(a, b) {
    return a * b / gcd(a, b);
  }
  var result = 1;
  for(var i = 2; i <= n; i++) {
    result = lcm(result, i);
  }
  return result;
}