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


	cpu	8086
	org	100h
section	.text
	mov	di,10 		; DI is the divisor to find digits 
	xor 	bp,bp		; Find first 20 Harshad numbers
	mov	cx,20
first:	call	next
	mov	ax,bp
	call	print
	loop	first
	mov	bp,1000		; Find first Harshad number > 1000
	call	next		; .. fall through (print and stop)
	mov	ax,bp
	;;;	Print the number in AX
print:	mov 	bx,buffer	; String buffer
.digit:	xor	dx,dx		; Divide by 10
	div	di
	add	dl,'0'		; Add ASCII 0 to remainder
	dec	bx
	mov	[bx],dl		; Store ASCII number
	test	ax,ax		; More digits?
	jnz	.digit
	mov	ah,9		; Print string using DOS
	mov	dx,bx
	int	21h
	ret 
	;;;	Let BP be the first Harshad number above BP
next:	inc	bp
	mov	ax,bp		; Keep a copy
	xor	bx,bx		; Sum
.digit:	xor	dx,dx		; Divide by 10
	div	di
	add	bx,dx		; Add remainder to sum
	test	ax,ax		; More digits?
	jnz	.digit
	mov	ax,bp		; Is it a Harshad number?
	xor	dx,dx
	div	bx
	test	dx,dx		; If not, try next number 
	jnz	next		
	ret 
section	.data
	db	'*****'
buffer:	db	13,10,'$'