Skip to content

Commit 53297f7

Browse files
Update sol1.py
1 parent 9a38038 commit 53297f7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Diff for: project_euler/problem_122/sol1.py

+24
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@
33
44
Efficient 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+
630
It uses the fact that for rather small n, applicable for this problem, the solution
731
for each number
832
can be formed by increasing the largest element.

0 commit comments

Comments
 (0)