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


n = 0
m = 1
first20 = ""
after1k = ""
 
Do
	If IsHarshad(m) And n <= 20 Then
		first20 = first20 & m & ", "
		n = n + 1
		m = m + 1
	ElseIf IsHarshad(m) And m > 1000 Then
		after1k = m
		Exit Do
	Else
		m = m + 1
	End If
Loop
 
WScript.StdOut.Write "First twenty Harshad numbers are: "
WScript.StdOut.WriteLine
WScript.StdOut.Write first20
WScript.StdOut.WriteLine
WScript.StdOut.Write "The first Harshad number after 1000 is: "
WScript.StdOut.WriteLine
WScript.StdOut.Write after1k
 
Function IsHarshad(s)
	IsHarshad = False
	sum = 0
	For i = 1 To Len(s)
		sum = sum + CInt(Mid(s,i,1))
	Next
	If s Mod sum = 0 Then
		IsHarshad = True
	End If
End Function