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

74 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
id: 5900f3761000cf542c50fe89
title: 问题10素数的总和
challengeType: 5
videoUrl: ''
dashedName: problem-10-summation-of-primes
---
# --description--
低于10的素数之和为2 + 3 + 5 + 7 = 17.求出n以下所有素数的总和。
# --hints--
`primeSummation(17)`应该返回41。
```js
assert.strictEqual(primeSummation(17), 41);
```
`primeSummation(2001)`应该返回277050。
```js
assert.strictEqual(primeSummation(2001), 277050);
```
`primeSummation(140759)`应该返回873608362。
```js
assert.strictEqual(primeSummation(140759), 873608362);
```
`primeSummation(2000000)`应返回142913828922。
```js
assert.strictEqual(primeSummation(2000000), 142913828922);
```
# --seed--
## --seed-contents--
```js
function primeSummation(n) {
return true;
}
primeSummation(2000000);
```
# --solutions--
```js
function primeSummation(n) {
if (n < 3) { return 0 };
let nums = [0, 0, 2];
for (let i = 3; i < n; i += 2){
nums.push(i);
nums.push(0);
}
let sum = 2;
for (let i = 3; i < n; i += 2){
if (nums[i] !== 0){
sum += nums[i];
for (let j = i*i; j < n; j += i){
nums[j] = 0;
}
}
}
return sum;
}
```