<分区>
我有一道应用题要解决,但卡在了关键部分。
Convert the following English description into Python code.
Initialize n to be 100. Initialize numbers to be a list of numbers from 2 to n, but not including n. With results starting as the empty list, repeat the following as long as numbers contains any numbers.
Add the first number in numbers to the end of results.
Remove every number in numbers that is evenly divisible by (has no remainder when divided by) the number that you had just added to results.
How long is result?
When n is 100, the length of results is 25.
到目前为止,我已经了解设置 n = 100
和 range(2, 100)
,results = []
并且结果将是 results.append(numbers[])
中的附加情况,但我有一个心理障碍来计算“删除数字中可被数字整除的每个数字”添加到结果中”。
======几分钟后=======
正如 Michael0x2a 所说 - 当我必须使用 Eratosthenes 筛法实现找到从 2 到 n 的所有素数的算法时,这是一个问题。
我想我可以继续处理这个问题。
非常感谢你们的回答。