Files
gikf 7907f62337 fix(curriculum): clean-up Project Euler 121-140 (#42731)
* fix: clean-up Project Euler 121-140

* fix: corrections from review

Co-authored-by: Sem Bauke <46919888+Sembauke@users.noreply.github.com>

* fix: missing backticks

Co-authored-by: Kristofer Koishigawa <scissorsneedfoodtoo@gmail.com>

* fix: corrections from review

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>

* fix: missing delimiter

Co-authored-by: Sem Bauke <46919888+Sembauke@users.noreply.github.com>
Co-authored-by: Kristofer Koishigawa <scissorsneedfoodtoo@gmail.com>
Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
2021-07-16 21:38:37 +02:00

66 lines
1.2 KiB
Markdown
Raw Permalink 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: 5900f3e61000cf542c50fef9
title: 'Problem 122: Efficient exponentiation'
challengeType: 5
forumTopicId: 301749
dashedName: problem-122-efficient-exponentiation
---
# --description--
The most naive way of computing $n^{15}$ requires fourteen multiplications:
$$n × n × \ldots × n = n^{15}$$
But using a "binary" method you can compute it in six multiplications:
$$\begin{align}
& n × n = n^2\\\\
& n^2 × n^2 = n^4\\\\
& n^4 × n^4 = n^8\\\\
& n^8 × n^4 = n^{12}\\\\
& n^{12} × n^2 = n^{14}\\\\
& n^{14} × n = n^{15}
\end{align}$$
However it is yet possible to compute it in only five multiplications:
$$\begin{align}
& n × n = n^2\\\\
& n^2 × n = n^3\\\\
& n^3 × n^3 = n^6\\\\
& n^6 × n^6 = n^{12}\\\\
& n^{12} × n^3 = n^{15}
\end{align}$$
We shall define $m(k)$ to be the minimum number of multiplications to compute $n^k$; for example $m(15) = 5$.
For $1 ≤ k ≤ 200$, find $\sum{m(k)}$.
# --hints--
`efficientExponentation()` should return `1582`.
```js
assert.strictEqual(efficientExponentation(), 1582);
```
# --seed--
## --seed-contents--
```js
function efficientExponentation() {
return true;
}
efficientExponentation();
```
# --solutions--
```js
// solution required
```