File tree Expand file tree Collapse file tree 1 file changed +11
-17
lines changed
project_euler/problem_810 Expand file tree Collapse file tree 1 file changed +11
-17
lines changed Original file line number Diff line number Diff line change 2727
2828"""
2929
30+ from array import array
31+
3032
3133def xor_multiply (op_a : int , op_b : int ) -> int :
3234 """
@@ -108,23 +110,17 @@ def find_xor_prime(rank: int) -> int:
108110 41
109111 """
110112 total , degree = 0 , 1
111- while True :
112- count = count_irreducibles (degree )
113- if total + count > rank :
114- break
115- total += count
113+ while total + count_irreducibles (degree ) < rank :
114+ total += count_irreducibles (degree )
116115 degree += 1
117116
118117 limit = 1 << (degree + 1 )
119118
120- sieve = [True ] * limit
121- sieve [0 ] = sieve [1 ] = False
122-
123- for even in range (4 , limit , 2 ):
124- sieve [even ] = False
119+ sieve = array ("B" , [1 ]) * limit
120+ sieve [0 ] = sieve [1 ] = 0
125121
126- current = 1
127- for i in range (3 , limit , 2 ):
122+ current = 0
123+ for i in range (2 , limit ):
128124 if sieve [i ]:
129125 current += 1
130126 if current == rank :
@@ -135,12 +131,10 @@ def find_xor_prime(rank: int) -> int:
135131 prod = xor_multiply (i , j )
136132 if prod >= limit :
137133 break
138- sieve [prod ] = False
139- j += 2
134+ sieve [prod ] = 0
135+ j += 1
140136
141- raise ValueError (
142- "Failed to locate the requested XOR-prime within the computed limit"
143- )
137+ raise ValueError ("Failed to locate the requested XOR-prime" )
144138
145139
146140def solution (limit : int = 5000001 ) -> int :
You can’t perform that action at this time.
0 commit comments