[Python-ideas] Is this PEP-able? for X in ListY while conditionZ:

Joshua Landau joshua.landau.ws at gmail.com
Wed Jul 3 01:20:54 CEST 2013


On 2 July 2013 23:35, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Oscar Benjamin wrote:
>>>> def primes():
>> primes_seen = []
>> for n in count(2):
>> if all(n % p for p in primes_seen):
>> yield n
>> primes_seen.append(n)
>>>> This algorithm is actually even poorer as it doesn't stop at sqrt(n).
>>> Nor should it! When you're only dividing by primes, you
> can't stop at sqrt(n), you have to divide by *all* the
> primes less than n. Otherise you could miss a prime
> factor greater than sqrt(n) whose cofactor is not prime.

I'm not convinced.
Say you have 7 * 6. That is 7 * 3 * 2, so if 7 has a cofactor of 6
then 2 is a factor. The proof can be generalised.


More information about the Python-ideas mailing list

AltStyle によって変換されたページ (->オリジナル) /