1
1
"""
2
2
Project Euler Problem 686: https://projecteuler.net/problem=686
3
3
4
- 2** 7 = 128 is the first power of two whose leading digits are "12".
5
- The next power of two whose leading digits are "12" is 2** 80.
4
+ 2^ 7 = 128 is the first power of two whose leading digits are "12".
5
+ The next power of two whose leading digits are "12" is 2^ 80.
6
6
7
7
Define p(L,n) to be the nth-smallest value of j such that
8
- the base 10 representation of 2** j begins with the digits of L.
8
+ the base 10 representation of 2^ j begins with the digits of L.
9
9
10
10
So p(12, 1) = 7 and p(12, 2) = 80.
11
11
@@ -24,8 +24,8 @@ def log_difference(number: int) -> float:
24
24
large exponents is time consuming. Hence we use log to reduce compute time.
25
25
26
26
We can find out that the first power of 2 with starting digits 123 is 90.
27
- Computing 2** 90 is time consuming.
28
- Hence we find log(2** 90) = 90*log(2) = 27.092699609758302
27
+ Computing 2^ 90 is time consuming.
28
+ Hence we find log(2^ 90) = 90*log(2) = 27.092699609758302
29
29
But we require only the decimal part to determine whether the power starts with 123.
30
30
SO we just return the decimal part of the log product.
31
31
Therefore we return 0.092699609758302
@@ -43,14 +43,12 @@ def log_difference(number: int) -> float:
43
43
return difference
44
44
45
45
46
- # series = 90, 379, 575, 864, 1060, 1545, 1741, 2030, 2226, 2515
47
-
48
46
49
47
def solution (number : int = 678910 ) -> int :
50
48
"""
51
49
This function calculates the power of two which is nth (n = number)
52
50
smallest value of power of 2
53
- such that the starting digits of the 2** power is 123.
51
+ such that the starting digits of the 2^ power is 123.
54
52
55
53
For example the powers of 2 for which starting digits is 123 are:
56
54
90, 379, 575, 864, 1060, 1545, 1741, 2030, 2226, 2515 and so on.
@@ -64,7 +62,7 @@ def solution(number: int = 678910) -> int:
64
62
lowerbound = log(1.23), upperbound = log(1.24)
65
63
because we need to find the powers that yield 123 as starting digits.
66
64
67
- log(1.23) = 08990511143939792, log(1,24) = 09342168516223506.
65
+ log(1.23) = 0. 08990511143939792, log(1,24) = 0. 09342168516223506.
68
66
We use 1.23 and not 12.3 or 123, because log(1.23) yields only decimal value
69
67
which is less than 1.
70
68
log(12.3) will be same decimal vale but 1 added to it
0 commit comments