Peter wrote the stuff below in the comment of the previous post.
Okay, I am cooking dinner but before I started I wrote the following. Meant to carefully check it for more silly errors after dinner but what the hey, here goes:
The follows shows that we can build numbers
which satisfy the rule that a number consisting of
digits, all 1, is divisible by
with no remainder.
This means we can define any
so that a number
consisting of
digits, all 1, is divisible by its digit sum if we choose a
that satisfies
.
This does not mean that any number for which this rule works is necessarily of the form
.
Theorem
Working in base
, let
,
a positive integer and g a positive integer satifying
.
Define
using:


and
using:


where
.
Then,

Proof
Take the following results as proven:
1. If an integer
is written in base
, and
is an integer with
, then
is divisible by
if and only if the sum of its digits is divisible by
. (Special case:
and
or
).
2. If
and
then 
Prove P(0):

Let


Then,

Assume P(k) is true:

Then prove P(k+1):

So

Since P(k) is true, we have

Then consider
.
Remember
is an
digit number.
From result 1, if an integer
is written in base
, and
is an integer with
, then
is divisible by
if and only if the sum of its digits is divisible by
.
Remember
, so the number of digits of
,
, is divisible by
. Therefore
is divisible by
. Let
which
some positive integer with
.
(Since
involves only positive terms to the power of
and
(since
),
).
So we can express

and since
,

Then, since
,

Now using result 2 we have


So

and
so

…and there’s more…
Okay, there are mistakes in the \latex here, such as
should be
, (but I’m getting better) and in the maths, such as when I say if
is divisible by
then
can be written as
for some
.
Anyway, in correcting it I think I have found a necessary and sufficient test for whether an n-digit number works (it hinges on proving another result). This is below with some examples. Once it is posted I will not doubt find a load of errors!
To test if an
-digit number with all digits equal is divisible by the sum of its digits:
Working in base
, let
be a positive integer satisfying
and define an n-digit number:

for some
with
.
Find
such that
(i.e., find the power of
that gives the greatest number not greater than
). Then we can write
as

for t some positive integer.
Calculate


Then
if and only if
That is, if both
and
or
.
Note that if
then
and this is an earlier result we had. The cases that didn’t fit that pattern are those where
such as 202 (20) in base 3 or 111 in base 10.
Examples
1. In base 10, let
so
. Then
and
.
written as
.
Calculate:


Since
and
are both
,
is divisible by its digit sum.
2. In base 10, let
so
. Then
and
.
written as
.\\
Calculate:


So
so a
digit number of this form is not divisible by its digit sum.
3. In base 10, let
so
. Then
and
.
Calculate:


So
so a
digit number does not work.
4. In base 10, let
(notice
cannot be written as
for any integer
) so
has
digits. Then
and
.
Calculate:


So
so a
digit number is divisible by the sum of its digits (N.B. even though
and
and not each equal to
).
5. In base 3, let
so
. (In base 10,
,
). Then
and
so we write
.
Calculate:


Since
and
are both
, a
digit number of this form is divisible by its digit sum.
6. In base 3, let
so
. (In base 10,
,
). Then
(base 10:
) and
(in base 10,
) so we write
(in base 10,
.
Calculate:
(In base 10:
)
(In base 10:
)
Since
,
is not divisible by its digit sum.
7. In base 3, let
so
. (In base 10,
,
). (N.B.
cannot be expressed as
for any integer
). Then
and
(in base 10,
and
) so we write
(in base 10
).
Calculate:
(In base 10:
)
(In base 10:
)
Since
,
is divisible by its digit sum.
Let’s have a stab at a proof:
Working in base
, let
be a positive integer satifying
and define an n-digit number:

for some
with
.
Then
if and only if
(since
).
Find
such that
(i.e., find the power of
that gives the greatest number not greater than
). Then we can write
as

for t some positive integer.
Let

We use (without proving) the following result:
If and only if
and
then
Then

if and only if
Then
if and only if
Not sure about cases where
is not unique.