Anonymous user
Brilliant numbers: Difference between revisions
→{{header|Python}}: change to numpy for efficiency
(added python) |
(→{{header|Python}}: change to numpy for efficiency) |
||
Line 933:
=={{header|Python}}==
Using primesieve and numpy modules
<lang Python>from primesieve.numpy import primes
from math import isqrt
import numpy as np
max_order = 9
def smallest_brilliant(
pos = 1
n = len(blk)▼
best = blk[-1]**2▼
for blk in
▲ n = len(blk)
if blk[-1]*blk[-1] < lb:
pos += n*(n + 1)//2
continue
if not
return blk[0]*blk[0],
idx = np.searchsorted(blk, q, 'right')
sel = idx <
p, idx = p[sel],
q =
hi = j▼
▲ else:
lo = j + 1▼
sel = q
p, q, idx
pos += np.sum(idx - np.arange(len(idx)))
return
p = 0
for i in range(100):
p,
print(f'
for
p, pos = smallest_brilliant(thresh)
print(f'
{{out}}
<pre>
Above 10^ 1: 10 at #4
Above 10^ 3: 1003 at #74
Above 10^ 4: 10201 at #242
Above 10^ 5: 100013 at #2505
Above 10^ 6: 1018081 at #10538
Above 10^ 7: 10000043 at #124364
Above 10^ 8: 100140049 at #573929
Above 10^ 9: 1000000081 at #7407841
Above 10^10: 10000600009 at #35547995
Above 10^11: 100000000147 at #491316167
Above 10^12: 1000006000009 at #2409600866
Above 10^13: 10000000000073 at #34896253010
Above 10^14: 100000380000361 at #174155363187
Above 10^15: 1000000000000003 at #2601913448897
Above 10^16: 10000001400000049 at #13163230391313
Above 10^17: 100000000000000831 at #201431415980419</pre>
=={{header|Raku}}==
|