Skip to content

Commit aa30a0b

Browse files
Add solution for Problem 810
1 parent 743830a commit aa30a0b

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

project_euler/problem_810/sol1.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"""
2929

3030

31-
def xor_multiply(a: int, b: int) -> int:
31+
def xor_multiply(op_a: int, op_b: int) -> int:
3232
"""
3333
Perform XOR multiplication of two integers, equivalent to polynomial
3434
multiplication in GF(2).
@@ -37,33 +37,33 @@ def xor_multiply(a: int, b: int) -> int:
3737
15
3838
"""
3939
res = 0
40-
while b:
41-
if b & 1:
42-
res ^= a
43-
a <<= 1
44-
b >>= 1
40+
while op_b:
41+
if op_b & 1:
42+
res ^= op_a
43+
op_a <<= 1
44+
op_b >>= 1
4545
return res
4646

4747

48-
def divisors(n: int) -> set[int]:
48+
def divisors(num: int) -> set[int]:
4949
"""
50-
Return all divisors of n (excluding 0).
50+
Return all divisors of `num` (excluding 0).
5151
5252
>>> divisors(12)
5353
{1, 2, 3, 4, 6, 12}
5454
"""
5555
s = {1}
56-
for i in range(2, int(n**0.5) + 1):
57-
if n % i == 0:
56+
for i in range(2, int(num**0.5) + 1):
57+
if num % i == 0:
5858
s.add(i)
59-
s.add(n // i)
60-
s.add(n)
59+
s.add(num // i)
60+
s.add(num)
6161
return s
6262

6363

6464
def mobius_table(n: int) -> list[int]:
6565
"""
66-
Generate Möbius function values from 1 to n.
66+
Generate a variant of Möbius function values from 1 to n.
6767
6868
>>> mobius_table(10)[:6]
6969
[0, 1, -1, -1, 0, -1]
@@ -85,19 +85,19 @@ def mobius_table(n: int) -> list[int]:
8585
return mob
8686

8787

88-
def count_irreducibles(d: int) -> int:
88+
def count_irreducibles(deg: int) -> int:
8989
"""
90-
Count the number of irreducible polynomials of degree d over GF(2)
91-
using the Möbius function.
90+
Count the number of irreducible polynomials of degree `deg` over GF(2)
91+
using the variant of Möbius function.
9292
9393
>>> count_irreducibles(3)
9494
2
9595
"""
96-
mob = mobius_table(d)
96+
mob = mobius_table(deg)
9797
total = 0
98-
for div in divisors(d) | {d}:
99-
total += mob[div] * (1 << (d // div))
100-
return total // d
98+
for div in divisors(deg) | {deg}:
99+
total += mob[div] * (1 << (deg // div))
100+
return total // deg
101101

102102

103103
def find_xor_prime(rank: int) -> int:

0 commit comments

Comments
 (0)