How to resolve the algorithm Minimum multiple of m where digital sum equals m step by step in the Nim programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Minimum multiple of m where digital sum equals m step by step in the Nim programming language
Table of Contents
Problem Statement
Generate the sequence a(n) when each element is the minimum integer multiple m such that the digit sum of n times m is equal to n.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Minimum multiple of m where digital sum equals m step by step in the Nim programming language
Source code in the nim programming language
import std/strutils
func digitSum(n: Natural): int =
## Return the sum of digits of "n".
var n = n
while n != 0:
result.inc n mod 10
n = n div 10
iterator a131382(count: Natural): (int, int) =
## Yield the index and value of the first "count" elements
## of the sequence.
for n in 1..count:
var m = 1
while digitSum(m * n) != n:
inc m
yield (n, m)
for idx, n in a131382(70):
stdout.write align($n, 9)
if idx mod 10 == 0: stdout.write '\n'
You may also check:How to resolve the algorithm S-expressions step by step in the Perl programming language
You may also check:How to resolve the algorithm O'Halloran numbers step by step in the AppleScript programming language
You may also check:How to resolve the algorithm EKG sequence convergence step by step in the Phix programming language
You may also check:How to resolve the algorithm Flatten a list step by step in the Insitux programming language
You may also check:How to resolve the algorithm Find palindromic numbers in both binary and ternary bases step by step in the Racket programming language