Saturday, 30 June 2018

Harshad Numbers Revisited

On the 10th February 2017, I posted about Harshad numbers, also known as Niven numbers, that are defined to be those numbers that are divisible by the sum of their digits in a given base. The post featured 24786 which was the last of the right-truncatable Harshad numbers (in base 10). Since then I've not been reminded of such numbers until I only recently came across the Numbers Aplenty website (see recent post). The reason for the disappearance of the Harshad numbers from the OEIS is that they are relatively frequent and so do not appear in a search of its database. Only the following numbers are listed:

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30, 36, 40, 42, 45, 48, 50, 54, 60, 63, 70, 72, 80, 81, 84, 90, 100, 102, 108, 110, 111, 112, 114, 117, 120, 126, 132, 133, 135, 140, 144, 150, 152, 153, 156, 162, 171, 180, 190, 192, 195, 198, 200, 201, 204

However, the OEIS entry does contain a link to all the Harshad numbers less or equal to 100,000. There are 11,872 of them and so there density is slightly less than 12% in that range. My number for today, 25290, appears in that list in position number 3771. However, I was only aware of this because of the Numbers Aplenty entry for 25290. The OEIS is definitely limited when it comes to searching for properties of numbers in this region of the number line and beyond.

The Numbers Aplenty reference to Harshad numbers contains some interesting additional information to what I posted in my earlier blog. For example, it is possible to have at most twenty consecutive Niven numbers and this happens infinitely often. Below is a list of runs of up to 13:


Wikipedia states that more generally there are 2b but not 2b + 1 consecutive b-harshad numbers, so that for example there can be runs of up to 22 11-harshad numbers, 24 12-harshad numbers and so on. Harshad numbers fall into the category of recreational mathematics.

While it's rather easy to determine whether a number is Harshad or not, nonetheless here is the SAGE code that I developed to test "harshadness":
INPUT
#Test for Harshad Number, divisible by sum of digits
number=25290
sum=0
nu_str=str(number)
for d in nu_str:
    sum+=Integer(d)
if number % sum == 0:
    print(number, "is Harshad Number")
else:
    print(number, "is not a Harshad Number")
 
OUTPUT
(25290, 'is Harshad Number')

No comments:

Post a Comment