Brilliant numbers: Difference between revisions
Content added Content deleted
(Add Factor) |
(added python) |
||
Line 931: | Line 931: | ||
"3.3s" |
"3.3s" |
||
</pre> |
</pre> |
||
=={{header|Python}}== |
|||
<lang Python>from primesieve.numpy import primes |
|||
max_order = 9 |
|||
blocks = [primes(10**n, 10**(n + 1)) for n in range(max_order)] |
|||
def smallest_brilliant(thresh=0): |
|||
pos = 1 |
|||
for blk in blocks: |
|||
n = len(blk) |
|||
best = blk[-1]**2 |
|||
if best < thresh: |
|||
pos += n*(n + 1)//2 |
|||
continue |
|||
hi = n - 1 |
|||
for i, p in enumerate(blk): |
|||
if (prod := p*p) >= thresh: |
|||
best = min(prod, best) |
|||
break |
|||
lo = i |
|||
while hi > lo: |
|||
if p*blk[(j := (lo + hi)//2)] >= thresh: |
|||
hi = j |
|||
else: |
|||
lo = j + 1 |
|||
pos += hi - i |
|||
if (prod := p*blk[hi]) >= thresh: |
|||
best = min(best, prod) |
|||
return best, pos |
|||
p, first100 = 0, [] |
|||
for i in range(100): |
|||
p, pos = smallest_brilliant(p + 1) |
|||
first100.append(p) |
|||
print(f'First 100: {first100}') |
|||
for n in range(2*max_order): |
|||
p, pos = smallest_brilliant(10**n) |
|||
print(f'first above 10**{n:2d}: {p:18d} at position {pos:14d}')</lang> |
|||
{{out}} |
|||
<pre>First 100: [4, 6, 9, 10, 14, 15, 21, 25, 35, 49, 121, 143, 169, 187, 209, 221, 247, 253, 289, 299, 319, 323, 341, 361, 377, 391, 403, 407, 437, 451, 473, 481, 493, 517, 527, 529, 533, 551, 559, 583, 589, |
|||
611, 629, 649, 667, 671, 689, 697, 703, 713, 731, 737, 767, 779, 781, 793, 799, 803, 817, 841, 851, 869, 871, 893, 899, 901, 913, 923, 943, 949, 961, 979, 989, 1003, 1007, 1027, 1037, 1067, 1073, 1079, 10 |
|||
81, 1121, 1139, 1147, 1157, 1159, 1189, 1207, 1219, 1241, 1247, 1261, 1271, 1273, 1333, 1343, 1349, 1357, 1363, 1369] |
|||
first above 10** 0: 4 at position 1 |
|||
first above 10** 1: 10 at position 4 |
|||
first above 10** 2: 121 at position 11 |
|||
first above 10** 3: 1003 at position 74 |
|||
first above 10** 4: 10201 at position 242 |
|||
first above 10** 5: 100013 at position 2505 |
|||
first above 10** 6: 1018081 at position 10538 |
|||
first above 10** 7: 10000043 at position 124364 |
|||
first above 10** 8: 100140049 at position 573929 |
|||
first above 10** 9: 1000000081 at position 7407841 |
|||
first above 10**10: 10000600009 at position 35547995 |
|||
first above 10**11: 100000000147 at position 491316167 |
|||
first above 10**12: 1000006000009 at position 2409600866 |
|||
first above 10**13: 10000000000073 at position 34896253010 |
|||
first above 10**14: 100000380000361 at position 174155363187 |
|||
first above 10**15: 1000000000000003 at position 2601913448897 |
|||
first above 10**16: 10000001400000049 at position 13163230391313 |
|||
first above 10**17: 100000000000000831 at position 201431415980419 </pre> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |