Hopefully, the algorithm I used does not fall victim of overflow or rounding errors. Using repeated subtractions (and multiplications) until the number is small keeps the large number calculations as integer math instead of float.
The first several solutions:
341
645
1387
1905
2047
3277
4033
4369
4371
4681
5461
---
def divides(n,d):
""" bool Does d evenly divide N? """
import math
result = n
while result > d:
result = result - d * 10**int(math.log(result,10) - math.log(d,10))
return result%d == 0
big = 5500
for n in range(1,big):
if divides(2**n-2,n) and not divides(3**n-3,n):
print(n)
|
Posted by Larry
on 2023-06-19 13:53:18 |