How to resolve the algorithm Sequence: smallest number greater than previous term with exactly n divisors step by step in the Nim programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Sequence: smallest number greater than previous term with exactly n divisors step by step in the Nim programming language
Table of Contents
Problem Statement
Calculate the sequence where each term an is the smallest natural number greater than the previous term, that has exactly n divisors.
Show here, on this page, at least the first 15 terms of the sequence.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Sequence: smallest number greater than previous term with exactly n divisors step by step in the Nim programming language
Source code in the nim programming language
import strformat
const MAX = 15
func countDivisors(n: int): int =
var i = 1
var count = 0
while i * i <= n:
if n mod i == 0:
if i == n div i:
inc count
else:
inc count, 2
inc i
count
var i, next = 1
echo fmt"The first {MAX} terms of the sequence are:"
while next <= MAX:
if next == countDivisors(i):
write(stdout, fmt"{i} ")
inc next
inc i
write(stdout, "\n")
You may also check:How to resolve the algorithm Dot product step by step in the IDL programming language
You may also check:How to resolve the algorithm Terminal control/Display an extended character step by step in the Nim programming language
You may also check:How to resolve the algorithm Terminal control/Coloured text step by step in the Ruby programming language
You may also check:How to resolve the algorithm Arithmetic/Integer step by step in the QB64 programming language
You may also check:How to resolve the algorithm Wasteful, equidigital and frugal numbers step by step in the Phix programming language