The Harshad or Niven numbers are positive integers ≥ 1 that are divisible by the sum of their digits.

For example,   42   is a Harshad number as   42   is divisible by   (4 + 2)   without remainder.

Assume that the series is defined as the numbers in increasing order.



Task

The task is to create a function/method/procedure to generate successive members of the Harshad sequence.

Use it to:

   list the first 20 members of the sequence,   and
   list the first Harshad number greater than 1000.


Show your output here.



Related task
   Increasing gaps between consecutive Niven numbers


See also
    OEIS: A005349


Public Sub Main()
Dim siCount, siLoop, siTotal, siCounter As Short
Dim sNo, sTemp As String
Dim sHold, sNiven As New String[]
 
For siCount = 1 To 1500
  sNo = Str(siCount)
  For siLoop = 1 To Len(sNo)
    sHold.Add(Mid(sNo, siLoop, 1))
  Next
  For Each sTemp In sHold
    siTotal += Val(sTemp)
  Next
  If siCount Mod siTotal = 0 Then 
    Inc siCounter
    If siCounter < 21 Or siCount > 1000 Then
      sNiven.Add(Str(siCount))
      If siCount > 1000 Then Break
    Endif
  Endif
  siTotal = 0
  sHold.Clear
Next
 
Print "First twenty Harshad numbers and the first Harshad number greater than 1000"
Print sNiven.Join(", ")
 
End