How to resolve the algorithm Super-d numbers step by step in the Nim programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Super-d numbers step by step in the Nim programming language
Table of Contents
Problem Statement
A super-d number is a positive, decimal (base ten) integer n such that d × nd has at least d consecutive digits d where For instance, 753 is a super-3 number because 3 × 7533 = 1280873331.
Super-d numbers are also shown on MathWorld™ as super-d or super-d.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Super-d numbers step by step in the Nim programming language
Source code in the nim programming language
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
You may also check:How to resolve the algorithm Cramer's rule step by step in the J programming language
You may also check:How to resolve the algorithm Animate a pendulum step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Temperature conversion step by step in the Scheme programming language
You may also check:How to resolve the algorithm Determine sentence type step by step in the Julia programming language
You may also check:How to resolve the algorithm System time step by step in the V (Vlang) programming language