freeCodeCamp/curriculum/challenges/english/08-coding-interview-prep/project-euler/problem-122-efficient-exponentiation.english.md
Valeriy 79d9012432 fix(curriculum): quotes in tests (#18828)
* fix(curriculum): tests quotes

* fix(curriculum): fill seed-teardown

* fix(curriculum): fix tests and remove unneeded seed-teardown
2018-10-20 23:32:47 +05:30

1.2 KiB
Raw Blame History

id, challengeType, title
id challengeType title
5900f3e61000cf542c50fef9 5 Problem 122: Efficient exponentiation

Description

The most naive way of computing n15 requires fourteen multiplications: n × n × ... × n = n15 But using a "binary" method you can compute it in six multiplications: n × n = n2n2 × n2 = n4n4 × n4 = n8n8 × n4 = n12n12 × n2 = n14n14 × n = n15 However it is yet possible to compute it in only five multiplications: n × n = n2n2 × n = n3n3 × n3 = n6n6 × n6 = n12n12 × n3 = n15 We shall define m(k) to be the minimum number of multiplications to compute nk; for example m(15) = 5. For 1 ≤ k ≤ 200, find ∑ m(k).

Instructions

Tests

tests:
  - text: <code>euler122()</code> should return 1582.
    testString: assert.strictEqual(euler122(), 1582, '<code>euler122()</code> should return 1582.');

Challenge Seed

function euler122() {
  // Good luck!
  return true;
}

euler122();

Solution

// solution required