In this universe, we know that the number system is the base of every mathematical model. When we talk about programming, we do deal with numbers and a way to manipulate the data variables through in-built functions and modules.
Lots of concepts are there from which one is a Harshad Number.
Another name of Harshad numbers are Niven numbers.
Niven numbers in base n are also called n-Niven ( or n-Harshad) numbers.
The word “harshad” comes from the Sanskrit harṣa (joy) + da (give) means joy-giver.
D. R. Kaprekar, a mathematician from India defined Harshad numbers.
The term “Niven number” arose by Ivan M. Niven.
Definition:- Harshad number is the smallest integer number in a given number base which is divisible by the sum of its digits when written in that base is known as Harshad number.
Steps To Find A Harshad Number
- Firstly, we need to accept the data value as input.
- Then we need to segregate the original number to get hold of all the digits that make up the number individually.
- Then, we do the sum of all the numbers that make up the required number.
- The last and final step is to divide the original number by the summation score.
- If we get any non-zero value as the output of the modulus operation, we can state that the original number is not a Harshad number.
- If the result is 0, it implies that the number is completely divisible by the summation score. Thus, we can conclude that an original number is a Harshad number.
Now let us take an example to understand the concept in a better way :-
Input number: 126
Digits of the number: 1, 2 and 6
Summation of digits: 1 + 2 + 6 = 9
Modulus operation: 126% 12 = 0
As the result of the mod, the operation is zero, we state that 126 is a Harshad number.
Now take some more examples:-
- If a number is 18, the sum of the digits is 1+ 8 = 9 and the number 18 is divisible by 9. So 18 is a Harshad number.
- If a number is 29, the sum of the digits is 2+ 9 = 11 and the number 29 is not divisible by 11. So 29 is not a Harshad number.
- Some of the Harshad numbers represented in base 10 are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 18, 20, 21, 24, 27, 30,………
- The Hardy – Ramanujan number i.e. 1729 is a Niven number in base 10 as it is divisible by ( 1 + 7 + 2 + 9) 19.
Note :-The most popular discovery remains the Hardy-Ramanujan number to this date. Hardy, the British mathematician said that he came in a taxi having the number ‘1729’to meet S Ramanujan in hospital which the British mathematician described “as rather a dull one”. Ramanujan replied to this saying, “No Hardy, it’s a very interesting number! It can be expressed as a sum of two positive integer cubes in n distinct ways i.e. 9³ + 10³ and 1³ + 12³. So, it is also known as the taxicab number.
Super Niven Number
If a number N not only divisible by the sum of its digits but also by the sum of any subset of its (nonzero) digits is known as Super Niven Number.
For Example:
- 68040
Divisible by 6, 8, 4, 6+8, 6+4, 4+8 and 6+4+8 so it is a Super Niven Number.
All-Harshad Number
A number that is a Harshad number is also known as an all- Harshad number in any number base.
Multiple Harshad Number
In 2005, Bloem said a Harshad number is known as a multiple Harshad number ( MHN) if a number divided by the sum of its digits produces another harshad number.
For Example:
- 6804
6804 ÷ 18 = 378
378 ÷ 18 = 21
21 ÷ 3 = 7
7 ÷ 7 = 1
Hence, 6804 is “MHN-4”
Note :- 6804 is not MHN-5 because1/1 = 1 (is not “another” harshad number)
Super-Harshad
If a number is divisible by its sum of digits s, and furthermore, the quotient is none other than the number s with its digits reversed.
For Example:- 1729
the sum of digits = 1 + 7 + 2 + 9 = 19 ,and indeed 1729=19×91 , with 91 being the number 19 with digits reversed.
Points To Remember
- All 1-digit numbers are Harshad numbers.
- 1, 2, 4, and 6 are only four all-Harshad numbers.
- The number 12 in all bases except octal is a Harshad number.
Properties Of A Harshad Number
- The base number and furthermore, its powers will always be a harshad number in its own base, since it will be represented as “10” and 1 + 0 = 1.
- All numbers whose base b digit sum divides b−1 are harshad numbers in base b.
- Given the divisibility test for 9, one might be tempted to generalize that all numbers divisible by 9 are also harshad numbers but the digits of n can only be added up once and n must be divisible by that sum for the purpose of determining the harshadness of n. So it is not a harshad number. For example, 99 is not a harshad number, since 9 + 9 = 18, and 99 is not divisible by 18.
- If a prime number is less than or equal to the base number then it is also a Harshad number Else the digits of the prime no will sum up to a no that is greater than one, but less than the prime no, and can not be divided. For example:Take a number 11,the sum of its digits = 1 + 1 = 2 and 11 is not divisible by 2. So, 11 is not harshad number in base 10.
- All factorials are not harshad numbers although the sequence of factorials starts with harshad numbers in base 10.Example: 432! Is the first that is not. (432! Has digit sum = 3897 = 32×433 in base 10, thus not dividing 432!)
Algorithm to determine a Harshad number
We need to follow the below algorithm to check for a Harshad Number.
- Accept the number as input.
- By storing the value of num in variable n, make a copy of the num.
- Calculate the remainder by dividing num with 10, if num is greater than 0.
- Addition of rem to a variable sum.
- Divide num by 10.
- To calculate the sum of all digits present in a given number, repeat the steps from 3 to 5.
- If n (copy of original number) is divisible by the sum, then given number is a Harshad number, otherwise given number is not a Harshad number.
Harshad Number Program In Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import java.util.Scanner; public class HarshadNumber{ public static void main(String args[]){ Scanner sc = new Scanner(System.in); System.out.print("Input a number : "); int num = sc.nextInt(); int x = num, y, sum = 0; while(x>0) { y = x%10; sum = sum + y; x = x/10; } if(num%sum == 0){ System.out.println(num+ " is a Harshad Number."); } else{ System.out.println(num+" is not a Harshad Number."); } } } |