N-smooth numbers: Difference between revisions

Added 11l
(Added 11l)
Line 52:
:*   OEIS entry:   [[oeis:A080683|A080683   23-smooth numbers]]
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>V primes = [2, 3, 5, 7, 11, 13, 17, 19, 23]
 
F isPrime(n)
I n < 2
R 0B
 
L(i) :primes
I n == i
R 1B
I n % i == 0
R 0B
I i * i > n
R 1B
print(‘Oops, ’n‘ is too large’)
R 0B
 
F init()
V s = 24
L s < 600
I isPrime(s - 1) & s - 1 > :primes.last
:primes.append(s - 1)
I isPrime(s + 1) & s + 1 > :primes.last
:primes.append(s + 1)
s += 6
 
F nsmooth(n, size)
assert(n C 2..521)
assert(size >= 1)
 
V bn = n
V ok = 0B
L(prime) :primes
I bn == prime
ok = 1B
L.break
assert(ok, ‘must be a prime number’)
 
V ns = [BigInt(0)] * size
ns[0] = 1
 
[BigInt] next
L(prime) :primes
I prime > bn
L.break
next.append(prime)
 
V indicies = [0] * next.len
L(m) 1 .< size
ns[m] = min(next)
L(i) 0 .< indicies.len
I ns[m] == next[i]
indicies[i]++
next[i] = :primes[i] * ns[indicies[i]]
 
R ns
 
init()
 
L(p) primes
I p >= 30
L.break
print(‘The first ’p‘ -smooth numbers are:’)
print(nsmooth(p, 25))
print()
 
L(p) primes[1..]
I p >= 30
L.break
print(‘The 3000 to 3202 ’p‘ -smooth numbers are:’)
print(nsmooth(p, 3002)[2999..])
print()
 
L(p) [503, 509, 521]
print(‘The 30000 to 3019 ’p‘ -smooth numbers are:’)
print(nsmooth(p, 30019)[29999..])
print()</lang>
 
{{out}}
<pre>
The first 2 -smooth numbers are:
[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216]
 
The first 3 -smooth numbers are:
[1, 2, 3, 4, 6, 8, 9, 12, 16, 18, 24, 27, 32, 36, 48, 54, 64, 72, 81, 96, 108, 128, 144, 162, 192]
 
The first 5 -smooth numbers are:
[1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, 36, 40, 45, 48, 50, 54]
 
The first 7 -smooth numbers are:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, 28, 30, 32, 35, 36]
 
The first 11 -smooth numbers are:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 27, 28, 30, 32]
 
The first 13 -smooth numbers are:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28]
 
The first 17 -smooth numbers are:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 24, 25, 26, 27]
 
The first 19 -smooth numbers are:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 26]
 
The first 23 -smooth numbers are:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
 
The first 29 -smooth numbers are:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
 
The 3000 to 3202 3 -smooth numbers are:
[91580367978306252441724649472, 92829823186414819915547541504, 94096325042746502515294076928]
 
The 3000 to 3202 5 -smooth numbers are:
[278942752080, 279936000000, 281250000000]
 
The 3000 to 3202 7 -smooth numbers are:
[50176000, 50331648, 50388480]
 
The 3000 to 3202 11 -smooth numbers are:
[2112880, 2116800, 2117016]
 
The 3000 to 3202 13 -smooth numbers are:
[390000, 390390, 390625]
 
The 3000 to 3202 17 -smooth numbers are:
[145800, 145860, 146016]
 
The 3000 to 3202 19 -smooth numbers are:
[74256, 74358, 74360]
 
The 3000 to 3202 23 -smooth numbers are:
[46552, 46575, 46585]
 
The 3000 to 3202 29 -smooth numbers are:
[33516, 33524, 33534]
 
The 30000 to 3019 503 -smooth numbers are:
[62913, 62914, 62916, 62918, 62920, 62923, 62926, 62928, 62930, 62933, 62935, 62937, 62944, 62946, 62951, 62952, 62953, 62957, 62959, 62964]
 
The 30000 to 3019 509 -smooth numbers are:
[62601, 62602, 62604, 62607, 62608, 62609, 62611, 62618, 62620, 62622, 62624, 62625, 62626, 62628, 62629, 62634, 62640, 62643, 62645, 62646]
 
The 30000 to 3019 521 -smooth numbers are:
[62287, 62288, 62291, 62292, 62300, 62304, 62307, 62308, 62310, 62315, 62320, 62321, 62322, 62325, 62328, 62329, 62330, 62331, 62335, 62336]
 
</pre>
 
=={{header|C}}==
1,481

edits