Brilliant numbers: Difference between revisions
Content added Content deleted
(→{{header|Python}}: change to numpy for efficiency) |
m (→{{header|Python}}: changed silly var name; explains why stop at 10^17) |
||
Line 933: | Line 933: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
Using primesieve and numpy modules |
Using primesieve and numpy modules. If program is run to above 10<sup>18</sup> it overflows 64 bit integers (that's what primesieve module backend uses internally). |
||
<lang Python>from primesieve.numpy import primes |
<lang Python>from primesieve.numpy import primes |
||
Line 940: | Line 940: | ||
max_order = 9 |
max_order = 9 |
||
blocks = [primes(10**n, 10**(n + 1)) for n in range(max_order)] |
|||
def smallest_brilliant(lb): |
def smallest_brilliant(lb): |
||
Line 946: | Line 946: | ||
root = isqrt(lb) |
root = isqrt(lb) |
||
for blk in |
for blk in blocks: |
||
n = len(blk) |
n = len(blk) |
||
if blk[-1]*blk[-1] < lb: |
if blk[-1]*blk[-1] < lb: |