In recreational mathematics, a Harshad number (or Niven number) in a given number base, is an integer that is divisible by the sum of its digits when written in that base. Harshad numbers in base n are also known as n-Harshad (or n-Niven) numbers. Harshad numbers were defined by D. R. Kaprekar, a mathematician from India. The word "Harshad" comes from the Sanskrit harṣa (joy) + da (give), meaning joy-giver. The term “Niven number” arose from a paper delivered by Ivan M. Niven at a conference on number theory in 1977. All integers between zero and n are n-Harshad numbers.
Stated mathematically, let X be a positive integer with m digits when written in base n, and let the digits be ai (i = 0, 1, ..., m − 1). (It follows that ai must be either zero or a positive integer up to n − 1.) X can be expressed as
If there exists an integer A such that the following holds, then X is a Harshad number in base n:
A number which is a Harshad number in every number base is called an all-Harshad number, or an all-Niven number. There are only four all-Harshad numbers: 1, 2, 4, and 6 (The number 12 is a Harshad number in all bases except octal).