Super-d numbers: Difference between revisions
Content added Content deleted
(Replace `^` notation with actual superscripts in task description) |
|||
Line 920: | Line 920: | ||
super-8: 185423, 641519, 1551728, 1854230, 6415190, 12043464, 12147605, 15517280, 16561735, 18542300 |
super-8: 185423, 641519, 1551728, 1854230, 6415190, 12043464, 12147605, 15517280, 16561735, 18542300 |
||
super-9: 17546133, 32613656, 93568867, 107225764, 109255734, 113315082, 121251742, 175461330, 180917907, 182557181</pre> |
super-9: 17546133, 32613656, 93568867, 107225764, 109255734, 113315082, 121251742, 175461330, 180917907, 182557181</pre> |
||
=={{header|Nim}}== |
|||
{{libheader|bignum}} |
|||
Using only the standard library, we would be limited to "d = 2, 3, 4". So, here is the program using the third-party library "bignum". |
|||
<lang Nim>import sequtils, strutils, times |
|||
import bignum |
|||
iterator superDNumbers(d, maxCount: Positive): Natural = |
|||
var count = 0 |
|||
var n = 2 |
|||
let e = culong(d) # Bignum ^ requires a culong as exponent. |
|||
let pattern = repeat(chr(d + ord('0')), d) |
|||
while count != maxCount: |
|||
if pattern in $(d * n ^ e): |
|||
yield n |
|||
inc count |
|||
inc n, 1 |
|||
let t0 = getTime() |
|||
for d in 2..9: |
|||
echo "First 10 super-$# numbers:".format(d) |
|||
echo toSeq(superDNumbers(d, 10)).join(" ") |
|||
echo "Time: ", getTime() - t0</lang> |
|||
{{out}} |
|||
<pre>First 10 super-2 numbers: |
|||
19 31 69 81 105 106 107 119 127 131 |
|||
First 10 super-3 numbers: |
|||
261 462 471 481 558 753 1036 1046 1471 1645 |
|||
First 10 super-4 numbers: |
|||
1168 4972 7423 7752 8431 10267 11317 11487 11549 11680 |
|||
First 10 super-5 numbers: |
|||
4602 5517 7539 12955 14555 20137 20379 26629 32767 35689 |
|||
First 10 super-6 numbers: |
|||
27257 272570 302693 323576 364509 502785 513675 537771 676657 678146 |
|||
First 10 super-7 numbers: |
|||
140997 490996 1184321 1259609 1409970 1783166 1886654 1977538 2457756 2714763 |
|||
First 10 super-8 numbers: |
|||
185423 641519 1551728 1854230 6415190 12043464 12147605 15517280 16561735 18542300 |
|||
First 10 super-9 numbers: |
|||
17546133 32613656 93568867 107225764 109255734 113315082 121251742 175461330 180917907 182557181 |
|||
Time: 1 minute, 43 seconds, 647 milliseconds, 920 microseconds, and 938 nanoseconds</pre> |
|||
=={{header|Pascal}}== |
=={{header|Pascal}}== |