File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
project_euler/problem_122 Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 33
44Efficient Exponentiation
55
6+ The most naive way of computing n^15 requires fourteen multiplications:
7+
8+ n x n x ... x n = n^15.
9+
10+ But using a "binary" method you can compute it in six multiplications:
11+ n x n = n^2
12+ n^2 x n^2 = n^4
13+ n^4 x n^4 = n^8
14+ n^8 x n^4 = n^12
15+ n^12 x n^2 = n^14
16+ n^14 x n = n^15
17+
18+ <However it is yet possible to compute it in only five multiplications:
19+
20+ n x n = n^2
21+ n^2 x n = n^3
22+ n^3 x n^3 = n^6
23+ n^6 x n^6 = n^{12}
24+ n^12 x n^3 = n^{15}
25+
26+ We shall define m(k) to be the minimum number of multiplications to compute n^k; for example m(15) = 5.
27+
28+ Find sum_{k = 1}^200 m(k).
29+
630It uses the fact that for rather small n, applicable for this problem, the solution
731for each number
832can be formed by increasing the largest element.
You can’t perform that action at this time.
0 commit comments