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.4 KiB
Raw Blame History

id, title, challengeType, videoUrl, dashedName
id title challengeType videoUrl dashedName
5900f3891000cf542c50fe9c 问题29不同的权力 5 problem-29-distinct-powers

--description--

考虑2≤a≤5和2≤b≤5的ab的所有整数组合

22 = 4、23 = 8、24 = 16、25 = 32

32 = 9、33 = 27、34 = 81、35 = 243

42 = 16、43 = 64、44 = 256、45 = 1024

52 = 25、53 = 125、54 = 625、55 = 3125

如果然后按数字顺序放置它们并删除所有重复项则会得到以下15个不同术语的序列

48916252732648112524325662510243125

对于2≤a≤n和2≤b≤n由ab生成的序列中有多少个不同的项

--hints--

distinctPowers(15)应该返回177。

assert.strictEqual(distinctPowers(15), 177);

distinctPowers(20)应该返回324。

assert.strictEqual(distinctPowers(20), 324);

distinctPowers(25)应该返回519。

assert.strictEqual(distinctPowers(25), 519);

distinctPowers(30)应该返回755。

assert.strictEqual(distinctPowers(30), 755);

--seed--

--seed-contents--

function distinctPowers(n) {

  return n;
}

distinctPowers(30);

--solutions--

const distinctPowers = (n) => {
  let list = [];
  for (let a=2; a<=n; a++) {
    for (let b=2; b<=n; b++) {
      let term = Math.pow(a, b);
      if (list.indexOf(term)===-1) list.push(term);
    }
  }
  return list.length;
};