Skip to content

Commit 3ec91f3

Browse files
Update sol1.py
1 parent 53297f7 commit 3ec91f3

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Diff for: project_euler/problem_122/sol1.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@
88
n x n x ... x n = n^15.
99
1010
But using a "binary" method you can compute it in six multiplications:
11+
1112
n x n = n^2
1213
n^2 x n^2 = n^4
1314
n^4 x n^4 = n^8
1415
n^8 x n^4 = n^12
1516
n^12 x n^2 = n^14
1617
n^14 x n = n^15
1718
18-
<However it is yet possible to compute it in only five multiplications:
19+
However it is yet possible to compute it in only five multiplications:
1920
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}
21+
n x n = n^2
22+
n^2 x n = n^3
23+
n^3 x n^3 = n^6
24+
n^6 x n^6 = n^12
25+
n^12 x n^3 = n^15
2526
2627
We shall define m(k) to be the minimum number of multiplications to compute n^k; for example m(15) = 5.
2728

0 commit comments

Comments
 (0)