J
OURNAL DE
T
HÉORIE DES
N
OMBRES DE
B
ORDEAUX
L
ORENZ
H
ALBEISEN
N
ORBERT
H
UNGERBÜHLER
The Josephus problem
Journal de Théorie des Nombres de Bordeaux, tome
9, n
o2 (1997),
p. 303-318
<http://www.numdam.org/item?id=JTNB_1997__9_2_303_0>
© Université Bordeaux 1, 1997, tous droits réservés.
L’accès aux archives de la revue « Journal de Théorie des Nombres de Bordeaux » (http://jtnb.cedram.org/) implique l’accord avec les condi-tions générales d’utilisation (http://www.numdam.org/conditions). Toute uti-lisation commerciale ou impression systématique est constitutive d’une infraction pénale. Toute copie ou impression de ce fichier doit conte-nir la présente mention de copyright.
Article numérisé dans le cadre du programme Numérisation de documents anciens mathématiques
The
Josephus
Problem
par LORENZ HALBEISEN ET NORBERT
HUNGERBÜHLER
RÉSUMÉ. Nous donnons des formules
explicites
permettant de calculer les nombres deJosephus j (n, 2, i) and j (n, 3, i)
et four-nissant unemajoration
et une minorationexplicites
de j(n,
k,
i)
qui
ne diffèrent que d’auplus
2k - 2(dans
le cas k = 4, ces bornes sont mêmemeilleures).
Nous proposons aussi un nouvelalgorithme
pour le calcul de ces nombres baséprécisément
sur cesestimations.
ABSTRACT. We
give
explicit
non-recursive formulas to computethe
Josephus-numbers j(n, 2, i) and j(n, 3, i)
andexplicit
upperand lower bounds
for j(n, k, i) (where k ~ 4)
which differby
2k - 2(for
k = 4 the bounds are evenbetter).
Furthermore wepresent a new fast
algorithm
tocalculate j(n,
k,
i)
which is basedupon the mentioned bounds.
1. Introduction
The
Josephus
problem
in itsoriginal
form goes back to the Roman historian FlaviusJosephus
(see [3]).
In the Romano-Jewish conflict of 67 A.D.,
the Romans took the townJotapata
whichJosephus
wascommanding.
He and 40companions escaped
and weretrapped
in a cave.Fearing
capture
they
decided to kill themselves.
Josephus
and a friend did not agree with thatproposal
but were afraid to be open in theiropposition.
Sothey
suggested
thatthey
should arrange them in a circle and thatcounting
around thecircle in the same sense all the
time,
every third man should be killeduntil there was
only
one survivor who would kill himself.By
choosing
theposition
31 and 16 in thecircle,
Josephus
and hiscompanion
saved their lives.(How
Josephus
became Roman historian is anotherinteresting
story.)
Let us fix some notations in order to describe thisproblem generally.
We number the npositions
in the circleby
0,1, 2, ... , n -1
and startcounting
at number 0. Then every kth element is removed. We define
to be the number of the ith element which is removed
by
the process de-scribed above(see
theexample
inFigure
1).
FIGURE 1. The
Josephus
sequence for n =5, k
= 3.Numerous
aspects
of theJosephus problem
andproperties
of the functionj
are treated in the literature: In[5]
the structure of thepermutation
is
investigated.
In[7]
a recursion formula forj(n,
k,
n)
is derived(there
is some difference to ournotation)
and also some congruenceproperties
ofthe
Josephus
numbers. In[2]
a recursivealgorithm
isgiven
to calculate thefunction j
and to solve theequation
j(n,
k, i)
= I for i when n and k aregiven.
In[1]
aninterpretation
of theJosephus problem
isgiven
in termsof the
representation
of rational numbers over the rational base Note that the rational numberplays
animportant
role also in this work.However,
noexplicit
formula for thefunction j
is known. It is the aim of this article togive explicit
(non-recursive)
upper and lower bounds for the valueof j(n,
k,
i).
These bounds coincide in case k =2,
k = 3(and
hencethis
yields
anexplicit
formula in the mentionedcases)
and in the case k = 4 at least the so calledcollapsing
numbers are determinedexactly
such thatthe
resulting
formula is exact in most cases(however
it mayhappen,
thatupper and lower bound differ
by
1).
For k > 5 the upper and the lower bound differby
2k - 2 such that at least for circleslarger
than n = 2k - 2we can say who is not the ith element to be removed.
In Section 6 we also
present
a newalgorithm
tocompute j(n,
k,
1)
forgeneral
n,
k,
I which is based upon the formulas for the mentioned bounds.To finish this introduction we want to
clarify
what we meanby "explicit
Definition We
define
the setof
explicit functions f : ~ -->
ae(or
f :
IR -+as
follows:
v
f
isexplicit if f
is a constant(complex)
function
or theidentity,
9
if f
isexplicit
thenF(f)
isexplicit if
F is oneof
thefunctions
exp,log
(the
principal
branchand log(0) := 0)
or(if
f
is a realfunction)
floor,
9
if f
and g areexplicit
thenf
o g isexplicit if
o is oneof
thebinary
functions
+,
-, *(multiplication),
/
(division,
:= 0for
c EC),
o(composition).
A
function
f (nl,
... ,nk)
is said to beexplicit
in niif for
anyfixed
nj,i,
thefunction
ni Hf(nl,
.. , ,
nk)
isexplicit.
This definition suffices for our purposes since it contains also constructions
like
f (n)
=max(g(n), h(n)), f (n)
=Round(g(n))
oras one
easily
can see. But ingeneral
alarger
class is used to treat othertypes
of differenceequations
(see
e.g.[4]).
An
example
is the well-knownexplicit
formulawith
for the Fibonacci numbers which are
recursively given by
f (0)
=f (1)
=1,
f (n
+2)
=f (n
+1)
+f (n).
Of course, for concrete calculations one hasto
compute
anapproximation
for the number A eitherby A z
for somelarge
jo
orby
analgorithm
whichprovides
numericalapproximations
ofV5
(since
A -1 2 5 ).
In both cases the expense increases with the indexj
for which one wants to knowf ( j ).
2. A recursive formula for
j(n,
k,
i)
A
special
case of thefollowing
formula may be found e.g. in[7].
HoweverTHEOREM 1. For the
josephus function
thefollowing
recursion holdswith initial value
Remark:
By
"a mod b" we mean thenon-negative integer
remainder ofthe division of a
by
b.Proof: The formula
(2)
followsdirectly
from the definition. To see(1)
weproceed by
induction.Suppose,
we know the valueof j (n,
k,
i)
=: g.Hence,
if we startcounting
at number0,
the ith member removed is number g.Now Because
of j (n+ 1, k,1) _
in the first
step
number(k -
1) mod(n
+1)
is removed and for the secondstep
we startcounting
at number k. Therefore theproblem
is to find the ith member which is removed(after
removing
(k -1) mod(n
+1))
whenwe start
counting
at number k. But this is(g
+ +1).
So,
weget
(1).
L73. A recursive formula for the
collapsing
numbers cmConsider for fixed k > 1 and 1 > 0 and for variable n > I the recursive
with j(n, k,1) _
(k - 1)
mod n.DEFINITION.
t) k -
2 we call n acollapsing
number,
other-wise we call nregular.
The reason for this
terminology
is thatregular
numbers n are characterizedby
theproperty
thatif the
right
hand side exists. We claim that for the firstcollapsing
numbercl there holds
where
I,
I
denotes the closestinteger
numbergreater
orequal
the realFirst case: 1 + 1 is
collapsing.
This means,k,1 )
k -2,
which isequivalent
to I + 1 - k -1.Hence, 1
+ = 1 +1,
as claimed.k-1
Second case: I + 1 is not
collapsing.
In thiscase, j (I + 1,1k,1)
= k -1.Thus,
the first
collapsing
number is the smallestinteger
cl with theproperty,
thatk-1+k(cl-(l+1)) >
CI.Solving
for clyields
This establishes
(3).
Now let cm denote the mth
collapsing
number andFor
d1
we obtain the formulaTo see
this,
we consideragain
thefollowing
two cases:First case: I + 1 is a
collapsing
number. In this cased1
= j(l
+1, k,1) _
(x - 1) mod(l
+1) =
1) mod(l
+ since x -1 > z + 1. Second case: I + 1 is not acollapsing
number. In this case k - 1 I +1,
and
di
= k - 1 + = k -(1 + 1)) mod Cl =
( f ’+’ 1 -
k - +rw-l)
by
definition of cl andby
(3).
If then
by
the recursive formula of Theorem 1 we obtainHence,
tocompute j(n, k, n -
1)
it is sufficient to know the sequences cmand
dm .
Let us start with a recursive formula for cm and
dm
(for
fixed k and1).
If cm and
dm
are known for some m, then cm+l = cm + s where s is theleast
integer
such that s ~ k +dm >
cm + s anddm+l
=s(l~ -1)
+dm -
cm.Hence we obtain
and thus
It will be convenient to write the formula for cm+i in the form
with um e
~-(k - 2), ... ,
k -3,1~ -
2}.
Rewriting
the definition(8)
for aim we obtainThe
following
table which we need latergives
the values of and ~m if cmmod(k -1)
anddm
are known.Summary: Starting
with(3)
and(4)
we canrecursively
compute
thesequences cm,
dm
and am(using
either Table 1 or the formulas(6)-(9)).
Then j ( n, k, n - t )
isgiven by
(5) .
4. How does the sequence cm
grow?
Also for this section let k > 1 and I be fixed.
If 7
is a realnumber,
then:= y +
cwhere - 2
E 2
is suchthat -1 +
c is aninteger
number.Let us start with the
following
technical lemma:LEMMA 1. Let Qo, 7i?... be a sequence
of
real numbersand for
i =0,1, ...
let
pi(x)
E,j =o
Then the setsare convex
for
any m.Proof: The
proof
isby
induction: For m = 0 the assertion is trivial. Nowsuppose we have verified the
convexity
of theassigned
sets for m mo andsuppose that
convexity
(say
forM+)
fails to be true for the index mo anda sequence We may assume that ~o = 0 and that there exists an
xo > 0 with 0 and >
pi(xo)lxo
where E 8M+ .By
choosing
olappropriately
we may further assume that > 0. Now consider thefamily
:=Pi (x)/ x ( j =1, ... mo)
ofpolynomials.
For xothere holds
qi’(xo)
= +2Pi(XO)/Xg
0which contradicts the
convexity
of the sets M+ for the indexma -1.
0THEOREM 2. The limit a :=
t)m
(depending
on kand I)
exists and
for
all m E IN there holdsfor k
> 2 and cm = a - 2mfor
k = 2.Hence,
for
k E{2,3,4}
there holds , .. . ’" m.,Proof: 1.
Step:
By
induction weget
from(8)
thatHence there holds
Now
defines an
analytic
function and the convergence radius of the power seriesis > 1.
Thus,
weget
2.
Step:
For fixed h E 11V we define c~~ :=ch(1 -
k
and for m E{1,2,... h}
em := i.e. eh - ch . Now we will show that emis a
good approximation
for cm for 1 m h. Tosimplify
the notationlet qk :=
k
*-Note that
by
(9)
there holdsfor
arbitrary
jO,jl.
Consider thepolynomials
WeE
{-A+2,...~-2}andp,(l)=E~o~+m+i
E ~-k-~
2, ... ,
k - 2}.
Henceby
Lemma 1 we obtain that E[-k + 2, k - 2]
and hence that the
right
hand side of(14)
has a value in~-1
+~, 1 2013 k~.
Thus we have
The first
step
allows to pass to the limit h 2013~ oo in(16)
and we obtainNow suppose that for some m there holds
and hence
(by
changing
sign
ifnecessary).
Observe thatHence from Lemma 1 it follows that Qm+i = k - 2. Furthermore we claim that (7y = 0
for j
> m + 1. Infact,
if Uj is the first non-zero coefficientafter
then
0by
(19).
Wereplace aj
by
cr~
= Uj + 1 and crj+lby
= 1 withoutviolating
(18)
and(19)
if k > 2. We denotethe modified
polynomials by
ph.
It follows thatt)
> k - 2 and henceph(1 -
t)
> k - 2 for some hlarge
enough.
But this contradicts Lemma 1and 17i
= 0for j
> m + 1 is established. Thisimplies
that for allj
E IN there holds E IN which isclearly
impossible
if k > 2. Thus we have(10)
and(11)-(12)
followimmediately.
0Remarks:
(a)
Note that if the sequence(or
equivalently
the sequence~dm})
would beperiodic,
then a would be a rational number.(b)
As we can see from the secondstep
in the aboveproof
we can usethe
approximation
ah :=t)h
for Of and that then the assertions ofTheorem 2 hold with ah in
place
of a at least for indices m h. As a further fact we state thefollowing
LEMMA 2. For k = 5 the
following
is true: Let I befixed
and let cm be acollapsing
number which is amultiple of
4,
then there holdsProof:
Essentially
werepeat
theproof
of theprevious
theorem: Noticethat
~
E INimplies
am = 0by
Table 1. This allows to obtain a better estimate in(14):
In fact Lemma 1implies
now that]
E~- 5 ,15 ~
and hence the
right
hand side of(14)
has a value in~-25, 2~~.
D5. Some
special
casesIn this section we consider the cases when k
equals
2,
3 or 4 and the case when k > 5. The case when kequals
2 is very easy and we willgive
differentexplicit
(in
n andi)
formulas to calculatej(n, 2, i).
For kequals
3,
we willgive
anexplicit
(in n)
formula to calculatej(n,
3,
i).
If kequals
4,
although
we can calculate the
collapsing
numbers cmprecisely,
thecorresponding
explicit
formulagives only
anapproximation
j(n,
4,
i)
having
theproperty
that j (n, 4, i) E ~ j(n, 4, i), j(n, 4, i) + 1?.
Ingeneral
for k > 5 we obtainj (n, k, i)
Efi(n,
k,
2), ... , j(n,
k,
i)
+ 2k -2}.
The case when kequals
2:If k = 2 then
equation
(11)
states thatand because cl = 1 +
(I
+1)
= 21 + 1 weget
21 + 1 =2a,
hence a =2~
Because am = = 0 for all
m, j (n, 2, n - l )
= 2 -(n - c,.,.t )
wherec,.,.~
n
So, by
(21),
m - 1 = andfinally
If 1 =
0,
thenby
(22), j(n, 2, n)
=2(n -
2llog2nJ).
Thus weget
thebinary
code
of j (n,
2,
n)
if we first write n in thebinary code,
cancel theleading
"1"(note
that this is n -llog2
and thenjoin
to thisbinary
number a "0" at the end.(This
interpretation
of the formula2(n -
2llog2 nJ) can
be found in[1]).
Before we continue with
larger
values of1~,
we need thefollowing
lemma: LEM MA 3. For k > 3 there holds with -(and a
as inTheo-rem
1)
Proof: From Section 4 we infer
(i)
Suppose
Applying
Lemma 1 as in theproof
of Theorem 2 weimmediately
conclude e"~ -c"~ >
0.(ii)
Analogue
to(i).
0The case when k
equals
3:If k =
3,
thenequation
(11)
states that(23)
=round(em)
with e"~ = a ~
( 2 )’n.
Tocompute
j(n, 3, n- l)
by
(5)
it is sufficient to knowcm
satisfying
and thecorresponding
To find cm is easy:For n > 5 the
appropriate
m is either rn - 1 or rn whereNow
according
to Lemma 3 we finddm
E{0,1}
as follows:is
given by
(5).
Example:
Let us use the above method in theoriginal
Josephus problem
as described in theintroduction,
i.e. we want tocalculate j (41, 3, 41).
The value of a for k = 3 and 1 = 0 is a = 0.8111 ...(see
Theorem2).
1.
Step:
From(24)
we find m = 10 andby
(23)
Cm = 47 > 41. Thus m = 9and c9 = 31
(again
by
(23)).
2.
Step:
eg - c9 = 0.1827 ... > 0. Hencedg
= 0.3.
Step:
j(41,3,41)
= 3 ~(41 -
c9)
+dg
= 30(i.e.
position
31 if we startnumbering
at 1 rather than at0).
This was in factJosephus’
place!
DThe case when k
equals
4:For k = 4
equation
(11)
states thatwith e m = Of’
( 4 )m.
Toby
(5)
we wouldagain
needp
to know cm
satisfying
and thecorresponding
dm .
We find cm as above for k = 3: For n > 7 theappropriate
m is either 1 or fn where(use
(25)
to decide which one is theright
choice).
Unfortunately
there seems to be no(easy)
way tocompute
dm
E{0,1? 2}.
However
according
to Lemma 3 we find that:Now,
if we choose = 1 in the first case andd,.,.z
= 0 in the secondcase and define
j(n,4,n -I)
=4(n -
+ then we haveby
(5)
that~4~-~)e{j(~4~-~)J(~4,~-/)+!}.
We want to
emphasize
that in many cases we still can decide whichpossi-bility
is theright
one. For this purpose wegive
several lemmas:LEMMA 4. For am =
4cm
there holdsProof: The formula for follows
just
from definition(8).
Then(i)-(iv)
follow from Table 1. 1:1
LEMMA 5. For all I there is a number
k,
such thatfor
all n > n, thefollowing
is true:Proof: If s =
0,
then of course~k -1) mod n
is the first number which isremoved.
If s >
0,
then the first numberbelonging
to the set{~ 2013
l, o, l, ...
k -2}
which is removed is 1~ -1- s.For both cases if we choose ni
large enough,
the number k -1- s is removedtoo
early.
0As an immediate consequence of this lemma we
get:
COROLLARY. For
fixed
I and k there is an mo, such thatfor
all m > mothe
following
is true:Further we have
LEMMA 6. For all I there is a number n,
2::
k,
such thatfor
all n > ni thefollowing
is true:Proof: Like the
proof
of Lemma 5. DThe case when k > 5:
Here we can no
longer
compute
the sequenceexactly.
Butaccording
toTheorem 2 we still have that cm E It is now hard to say
anything
about thedm
but if we defineEm
:=im
:= 0and
j(n, k, n - I)
:=k(n -
cm)
+d,~
then we have thatj(n,k,n -1)
E~ j(n,
k, n -1), ... j(n, k, n - l)
+ 2k -2} (the
discussion of the case n =Zm
is left to the
reader).
Thus if n > 2k - 2 we can say at least which is notthe ith
position
to be removed.6. An
algorithm
tocompute
j(n, k, i)
4The
problem
in theprevious
section was tocompute
(for
4)
the
corresponding
cm with and the valueof dm.
Let us definecm :=
:= We denoted~
:=j.
Let be the number that is obtainedby iterating
(6)
and(7)
h-timesstarting
withc~
andd1n.
The idea is now thatcm+h ) I
growsexponentially
withh if
(cm, dm).
To be moreprecise,
let us define the matrixfor i E
{I? 2}
and
E{O, 1, ... , k-2}.
Starting
with h = 0 wekeep iterating
this matrix until there is
only
oneentry
left which satisfies 1. Then we may conclude thatThen
again by
(5)
we maycompute j(n, k, i).
Now we
give
arough
estimate for the number h of iterations of the matrixA which need to be carried out in order to decide c~ and
dm:
To do this we assume that the sequence ispseudo-random,
i.e. we assume thefollowing hypothesis:
HYPOTHESIS. Let
6j,;
be 1if
i= j
and 0 otherwise. Thenfor
all d E{0,1,...~-2}.-
/We assume that
cm
=cm and
d1n
=(the
other cases aresimilar).
So if we
compute
theJosephus
numberj(n, k, n - I) (n > cm)
withd1n
and compare with the
1),
we see that the difference is 1.With
( 1 )
we see that if the first timedm+r
= 0 occurs then the differenceof
j(n, k, n - 1)
(n
>cm+r )
gets 2,
and so on. Now ifthe difference has grown to a value
larger
than2k,
we may conclude thatICm+h -
2 and hence 1.Using
thehypothesis
A refined
analysis gives
a better bound for theexpected
value ofh, namely
E[h] k(2
+log k). (Notice
that similar results hold under much weakerassumptions
than theHypothesis)
Example:
Let uscalculate j(n,
k, n -
1)
for k =7,
1 = 2001 and theprime
number
. ---
---By
Theorem 2 we find a = 2001.41696981983172 ... and thenm = round = 280. With ei = we find
round(62so) =
log m
-11128552382382930685534 > n and hence we have to choose m = m -1=
279 such that
~e279~ n
l e28oJ.
Afteriterating
the matrixA~
19 timeswe find that
Thus C279 =
~e27s~
= 9538759184899654873315 andd279
= 4.Finally
weobtain
REFERENCES
[1]
Burde,
K.: "Das Problem der Abzählreime undZahlenentwicklungen
mit ge-brochenen Basen". J. of NumberTheory
26(1987), 192-209
[2]
Jakóbczyk,
F.: "On thegeneralized Josephus problem". Glasgow
Math. J. 14(1973),168-173
[3]
Josephus,
F.: "Thejewish
war, Book III". Translatedby
H. S.Thackeray,
Heinemann
(1927),
341-366, 387-391
[4]
Nörlund,
N. E.:"Vorlesungen
überDifferenzenrechnung",
Grundlehren d. math. Wissensch. 13,Springer,
Berlin 1924[5]
Robinson,
W. J.: "TheJosephus problem".
Math. Gazette 44(1960),
47-52[6]
RouseBall,
W. W.: "Mathematical recreations andessays".
Reprint
New York(1962), 32-36
[7]
Woodhouse,
D.: "The extendedJosephus
problem".
Rev. Mat.Hisp.-Amer.
Lorenz HALBEISEN Mathematik