0
我正在製作Eratosthenes的篩子算法,並且我成功了一些整數,如31和13195.所以我要去找primenumber爲600851475143.但Python表示整數太大而無法轉換爲C ssize_t。關於Python Eratosthenes的篩子,如果我可以做,如果我使用列表和int太大,怎麼辦
所以這裏是我的代碼。
x = 600851475143
i = 2
tmp_result = list(range(2, x+1))
result = []
while tmp_result:
n = 1
result.append(tmp_result[0])
base = tmp_result[0]
while base*n < x+1:
product=base*n
if product in tmp_result:
tmp_result.remove(product)
n = n + 1
else :
n = n + 1
print(result)
print(tmp_result)
我想知道,
在Python是太不能進行長長的名單?
什麼是C ssize_t?
` THX很多
「我要找到600851475143的素數」這是什麼意思?你是否在尋找主要因素?另外,請記住,從列表中刪除元素可能是O(n),因此您的Eratosthenes篩選效率極低。 –