find all multiplicands and multipliers for a number
Rustom Mody
rustompmody at gmail.com
Tue Apr 14 06:35:37 EDT 2015
On Tuesday, April 14, 2015 at 8:12:17 AM UTC+5:30, Paul Rubin wrote:
> Steven D'Aprano writes:
> > http://code.activestate.com/recipes/577821-integer-square-root-function/
>
> The methods there are more "mathematical" but probably slower than what
> I posted.
>
> Just for laughs, this prints the first 20 primes using Python 3's
> "yield from":
>
> import itertools
>
> def sieve(ps):
> p = ps.__next__()
> yield p
> yield from sieve(a for a in ps if a % p != 0)
>
> primes = sieve(itertools.count(2))
> print(list(itertools.islice(primes,20)))
>
> It's not that practical above a few hundred primes, probably.
Upto 490 its instantaneous
At 500 recursion stack overflows
[Yeah one can set the recursion limit]
More information about the Python-list
mailing list